Found 10483 Articles for Web Development

How to transform JSON text into a JavaScript object?

Mayank Agarwal
Updated on 28-Apr-2022 11:29:00

2K+ Views

In this article, we are going to explore a way to convert the JSON text into a JavaScript object. JSON, also known as JavaScript Object Notation, is a lightweight data-interchange format that is used for exchanging data over web browsers. JSON is derived from the JavaScript programming language but can be used by various other languages also including Python, Java, PHP, Ruby, etc. It is also language-dependent.A JSON mainly follows a key-value data format that saves a value associated with a key. A JSON object consists of curly braces ({}) at both ends to define the starting and ending of ... Read More

How to swap variables using Destructuring Assignment in JavaScript?

Mayank Agarwal
Updated on 26-Apr-2022 13:14:16

272 Views

The Destructuring assignment is a feature that was introduced in the ECMAScript 2015. This feature lets the user extract the contents of the array, and properties of an object into distinct variables without actually writing the repetitive codeThis assignment lets the expression unpack values from arrays, and properties into distinct variables.Example 1In the below example, we use the destructuring assignment to assign variables. In the example, we have two variables defined as first and second. In the method, we are destructing the variables to assign the variables of the array to x and y respectively.# index.html    Checking ... Read More

How to set the cursor to wait in JavaScript?

Mayank Agarwal
Updated on 26-Apr-2022 12:53:57

2K+ Views

In this article, we are going to look at some cursor settings and their behaviors. Currently, there are different kind of cursors as provided by any system that includes a pointer, hand, insert, wait, pointer-wait, and many others.With the help of this article, we would be able to configure the wait pointer when required. This pointer will prevent the user from clicking a button unnecessarily and stops any further execution of similar events until the previous event is completed.We can directly use the CSS property to display the cursor as waiting but since we need the dynamic impact on showing ... Read More

How to search a string for a pattern in JavaScript?

Mayank Agarwal
Updated on 07-Mar-2025 12:52:48

622 Views

Searching strings for specific patterns is a common task in JavaScript. Strings are data types and are represented as a sequence of characters. Searching patterns means verifying the presence of a specific pattern in a given string. A pattern would be a specific word, specific characters, and so on. JavaScript offers several powerful methods for pattern matching, such as inbuilt string methods and regular expressions. This article will guide you on how to search strings for specific patterns in JavaScript. Table of contents Searching strings for specific patterns in JavaScript can be done in the following ways: ... Read More

JavaScript: How to return True if the focus is on the browser tab page?

Alshifa Hasnain
Updated on 22-Jan-2025 00:45:44

2K+ Views

In this article, we will learn to check if the browser tab page is focused and under use or not in JavaScript. This is mainly required to record the user’s inactivity time on the app and then take any action upon it if required. Use Cases for Monitoring Browser Tab Focus Following are the use cases for monitoring browser tab focus and user inactivity − Prevent sending the network request if the page is not being used by the user as this would reduce the traffic on the server. This would ... Read More

How to return all matching strings against a RegEx in JavaScript?

Mayank Agarwal
Updated on 26-Apr-2022 12:39:51

439 Views

In this article, we will explore the essentials of a regular expression (RegEx) and how to compare other strings with this regex in JavaScript. We will learn how to identify a similar string with that of a regex and then subsequently return them. We can use the string.search() method to match the regular expression in a given string.Syntaxlet index = string.search(expression)Parametersstring − This is the string that will be searched in comparison with the expression.expression − This is the regular expression that will be used for checking with the original string.Example 1In the below example, we are going to compare ... Read More

How to use JavaScript to replace a portion of string with another value?

Mayank Agarwal
Updated on 26-Apr-2022 13:24:35

907 Views

In this article, we are going to explore replacing a portion of a string with another value using JavaScript. We can replace string parts in multiple ways. Below are some common methods −replace() methodsplit() methodjoin() methodLet’s discuss the above methods in detail.The replace() MethodThis is an inbuilt method provided by JavaScript that allows the user to replace a part of a string with some another string or a regular expression. However, the original string will remain the same as earlier.Syntaxstring.replace(searchvalue, newvalue)Parameterssearchvalue - It is used for searching a string in the whole string.newvalue - It will replace the searched string.The ... Read More

How to Remove Duplicate Elements from an Array in JavaScript?

Mayank Agarwal
Updated on 18-Nov-2024 16:29:05

2K+ Views

To remove duplicate elements from an array in Javascript can be achieved using various approaches. We will be understanding six different approaches in this article, which can be used according to our requirement in various cases. In this article we are having a Javascript array and our task is to remove duplicate elements from array in JavaScript. Approaches to Remove Duplicate Elements From an Array Here is a list of approaches to remove duplicate elements from an array in JavaScript which we will be discussing in this article with stepwise explanation and complete example codes. ... Read More

How to Toggle Password Visibility in JavaScript?

Mayank Agarwal
Updated on 26-Apr-2022 12:09:13

564 Views

In this article, we are going to hide the password with ****. The password can be shown by toggling its visibility by using a button. We will be creating a JavaScript function that will display the hidden password when the toggle button is clicked.ApproachOn clicking the toggle button the JavaScript function to display the password will be rendered.This will change the CSS property applied on the HTML input tag that will display the password.We can toggle again to hide the password again.ExampleIn the below example, we are toggling the visibility of the password using the checkboxcheckbox. On clicking the checkbox ... Read More

How to use JavaScript to play a video on Mouse Hover and pause on Mouseout?

Mayank Agarwal
Updated on 27-Apr-2022 09:53:24

6K+ Views

In this article, we will be exploring the event listeners and how to use them for pausing and playing a video. We will be using the mouse over and the mouseout events to control the video.The main element of this article includes playing the video whenever the mouse hovers over the video and stopping/pausing the video when the mouse is taken out of that div.For achieving this specific purpose, we will be using JavaScript that will record the events and play/pause the video.ApproachWe will attach a video to our HTML DOM element and then apply the mouse over and mouse ... Read More

Advertisements