Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Front End Technology Articles
Page 291 of 652
How to use map() on an array in reverse order with JavaScript?
The map() method creates a new array by transforming each element. Sometimes you need to process array elements in reverse order. Here are three effective approaches to achieve this. Introduction to map() Method Syntax array.map((element, index, array) => { return element + 20; }) Parameters element – The current array element being processed index – The index of the current element array – The original array being mapped Method 1: Reverse Array Then Map First reverse the array using reverse(), then apply map() to the reversed ...
Read MoreHow to validate an input is alphanumeric or not using JavaScript?
Validating whether an input contains only alphanumeric characters (letters and numbers, no spaces or special characters) is a common requirement in JavaScript applications. An alphanumeric string contains only numeric digits (0-9) and alphabetical characters (A-Z, a-z). Below are two effective approaches to validate alphanumeric strings in JavaScript. Using the charCodeAt() Method The charCodeAt() method returns the ASCII value of a character. We can iterate through each character and check if its ASCII value falls within the valid ranges: 48-57: Numeric characters (0-9) 65-90: Uppercase letters (A-Z) 97-122: Lowercase letters (a-z) Syntax ...
Read MoreHow to validate email address using RegExp in JavaScript?
Anyone can make a mistake while entering the email in the input field. So, it's the developer's responsibility to check if users have entered a valid email string. Many libraries are available to validate email addresses, which we can use with various JavaScript frameworks, but not with vanilla JavaScript. However, if we want to use any library, we need to use its CDN. Here, we will use the regular expression to validate the email address in vanilla JavaScript. Basic Email Validation Pattern We have used the below regular expression pattern in our first example to validate the email. ...
Read MoreHow to zoom in and zoom out images using JavaScript?
The zoom-in and zoom-out functionality is essential for image interaction. By zooming in, users can examine image details closely, while zooming out provides a broader view. This feature is particularly useful for reading small text, viewing detailed graphics, or navigating large images. In this tutorial, we will learn to implement zoom functionality for images using JavaScript by manipulating CSS properties. Using Height and Width Properties The most straightforward approach is to modify the image's height and width properties. By increasing these values, we zoom in; by decreasing them, we zoom out. Syntax // Zoom ...
Read MoreHow to skip over an element in .map()?
In JavaScript, we sometimes need to skip array elements while using the map() method. For example, we might want to map values from one array to another after performing mathematical operations only on finite values, or transform strings that meet specific criteria. Here are three effective approaches to skip over array elements while using the map() method. Using if-else Statement In the array.map() method, we can use an if-else statement to conditionally process elements. If an element meets our condition, we return the transformed value; otherwise, we return null or undefined. Syntax array.map((element) => ...
Read MoreHow to transform a JavaScript iterator into an array?
In JavaScript, iterators are objects that implement the iterator protocol, allowing you to traverse through collections like Sets, Maps, or custom iterables. Unlike arrays, you cannot access iterator elements by index, so converting iterators to arrays is often necessary for easier manipulation. Here are three effective methods to transform JavaScript iterators into arrays. Using the for-of Loop The for-of loop iterates through each element of an iterator. Inside the loop, you can access elements and push them to an array using the push() method. Syntax for (let element of iterator) { ...
Read MoreHow to transform a String into a function in JavaScript?
We have given a string and need to convert it into a function in JavaScript. Sometimes, we get mathematical or function expressions in the form of the string, and executing that expression, requires converting strings into the function expression. In this tutorial, we will learn different approaches to converting the given string into a functional or mathematical expression. Use the eval() method The eval() method takes the expression as a parameter and evaluates the expression. For example, if we pass the '2 + 2' string as a parameter of the eval() method, it returns 4 as it evaluates ...
Read MoreHow to uncheck a radio button using JavaScript/jQuery?
Sometimes, we require to uncheck a radio button using JavaScript or jQuery. For example, we use the radio button in the form. When the user presses the clear form button, we need to uncheck all radio buttons and allow again users to choose any option from the radio button. In this tutorial, we will learn various methods to uncheck single or multiple radio buttons using jQuery or JavaScript. Using JavaScript to Uncheck Radio Button We can access the radio button in JavaScript using id, tag, name or other ways. After that, we can uncheck the radio button's ...
Read MoreHow to change the value of a global variable inside of a function using JavaScript?
In JavaScript, variables can be declared with either global or local scope. Understanding how to modify global variables from within functions is essential for managing application state. Global Variables are declared outside any function and can be accessed from anywhere in the code. Local Variables are declared inside functions and are only accessible within that specific function scope. There are two main approaches to change global variable values inside functions: Direct assignment Using window object with bracket notation Method 1: Direct Assignment The most straightforward way is to directly assign a new value ...
Read MoreHow to change the ID of the element using JavaScript?
Generally, the ID given to any element in an HTML document is unique and can be assigned to an element only once. However, it is possible to change that ID later using JavaScript while following the same rule of uniqueness for the new ID. In this article, we will learn how to change the ID of an element using JavaScript. JavaScript provides the id property to get the ID of any element as well as to change or add a new ID to any HTML element in the document. Syntax The following syntax shows how to use ...
Read More