Found 6710 Articles for Javascript

How to stop forEach() method in JavaScript?

Shubham Vora
Updated on 12-Sep-2023 01:16:52

48K+ Views

In JavaScript, Programmers can use the forEach() method to iterate through the array of elements. We can call a callback function, which we can pass as a parameter of the forEach() method for every array element. Sometimes, we may require to stop the forEach() loop after executing the callback function for some elements. We can use the ‘break’ keyword with a normal loop to stop it, as shown below. for(let i = 0; i < length; i++){ // code if( some condition ){ break; } ... Read More

How to Create Query Parameters in JavaScript?

Shubham Vora
Updated on 16-Feb-2023 15:20:39

2K+ Views

Now, the question is why we need to create a query parameter using JavaScript. Let’s understand it via real-life examples. For example, if you go on amazon’s website and search for any product, you will see that it automatically appends your search query to the URL. It means we require to generate the query params from the search query. Also, we can allow users to select any value from the dropdown option. We can generate query parameters and redirect users to a new URL based on the selected value to get results. We will learn to create a query parameter ... Read More

How to create a hash from a string in JavaScript?

Shubham Vora
Updated on 16-Feb-2023 15:19:18

8K+ Views

Before we start, let’s understand the hash in JavaScript. The hash is also a string, but it's encrypted using a particular algorithm. Generally, we use the hash for security purposes. For example, Google stores users' emails and passwords in their database. Now, Google’s employees can access their database for development purposes. But can they get the user’s email and password from the database? No, because the password is stored in the hash form, and to decrypt the password, the employee needs the key which we used while creating the hash from the password string. So, in such a way, we ... Read More

How to create a dynamic length array with numbers and sum the numbers using JavaScript?

Shubham Vora
Updated on 16-Feb-2023 15:18:02

1K+ Views

In JavaScript, arrays are always dynamic in length. Like other programming languages, we don’t need to define the array's length while creating the array. So, we can create an array and push whatever number of elements we want in the JavaScript array. Here, we will create the dynamic length of the array and add numbers to that. After that, we will sum up all numbers. This tutorial will teach us to create a dynamic length array with numbers and sum the numbers using JavaScript. Use the for loop to sum all elements of the dynamic array We can iterate over ... Read More

How to create a dropdown list using JavaScript?

Shubham Vora
Updated on 16-Feb-2023 15:16:43

13K+ Views

We will learn to create a dropdown list using HTML and JavaScript below. Before starting with the article, let’s understand the dropdown list and why we need to use it. The dropdown list gives multiple choices to users and allows them to select one value from all options. However, we can do the same thing using multiple radio buttons, but what if we have hundreds of choices? Then we can use the dropdown menu. When users click the dropdown button, it opens all the choices, and users can select anyone. Also, the dropdown provides a better user experience than the ... Read More

How to compare two objects to determine if the first object contains equivalent property values to the second object in JavaScript?

Shubham Vora
Updated on 16-Feb-2023 15:10:32

1K+ Views

In JavaScript, the object contains various properties and methods. For every property, it contains a value. We need to compare the values of the property also to make the comparison between two objects. Here, we will learn to check if the first object contains all properties that the second object contains and compare the values for every property. Compare the object property values one by one The easiest way is to check for every property of the second object that the first object contains or not. If the first object contains that property, compare the values of both. It means ... Read More

How to Create Dark/Light Mode for a Website using JavaScript/jQuery?

Shubham Vora
Updated on 16-Feb-2023 15:07:34

7K+ Views

Dark mode is very important for any website. Users with different interests visit the websites. Some of them like dark mode, and some like light mode. According to one survey, around 70 to 80% of people like dark mode, and only 20 to 30% like light mode. So, it is necessary to create a dark mode for any website, allowing users to toggle between the dark and light modes. Below, we will create a simple webpage using HTML, CSS, and JavaScript. Also, we will learn to implement the light and dark modes using JavaScript and CSS. Syntax Users can follow ... Read More

How to zoom in and zoom out images using JavaScript?

Shubham Vora
Updated on 16-Feb-2023 17:04:15

10K+ Views

The zoom-in and zoom out is an important functionality for the image. We can see every single information of the image by zoom-in. Maybe, you can press the ‘ctrl’ and ‘+’ keys together to zoom in to your browser, and you can see everything looks bigger in the browser window. The zoom-in feature is useful for reading small texts on the screen also. So, there can be various use cases of zoom in and zoom out. In this tutorial, we will learn to zoom in and zoom out images using JavaScript. Use the height and width properties to ... Read More

How to validate email address using RegExp in JavaScript?

Shubham Vora
Updated on 16-Feb-2023 17:03:06

14K+ Views

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. Regex Used in Example 1 We have used the below regular expression pattern in example 1 to validate the email. let ... Read More

How to validate an input is alphanumeric or not using JavaScript?

Shubham Vora
Updated on 16-Feb-2023 17:01:46

12K+ Views

We have been given the task of validating the input string and need to check whether it is alphanumeric or not using JavaScript. The alphanumeric string contains only numeric and alphabetical characters, including uppercase or lowercase characters, and even it doesn’t contain any special characters or spaces. Below, we will see two approaches to validate an input string. Use the charCodeAt() method We can use the charCodeAT() method to get the ASCII value of any character. Here, we will iterate through every character of the string and check the ASCII value of every character. The ASCII code between 48 ... Read More

Advertisements