Found 6685 Articles for Javascript

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 26-Apr-2022 12:50:09

465 Views

In this article, we are going to search for a specific pattern and only by pass those string that matches the given pattern. We will be using the following approaches to achieve this functionality −Approach 1In this approach, we will be searching for a string that matches the given pattern and find their indexes from the string. The string.search() is an inbuilt method provided by JavaScript for searching a string. We can also pass a regular expression or a normal string in this method.Syntaxstr.search( expression )Parametersstr − defines the string that needs to be compared.expression − defines the string expression ... Read More

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

Mayank Agarwal
Updated on 26-Apr-2022 12:45:59

979 Views

In this article, we are going to explore how to check if the browser tab page is focused and under use or not. This is mainly required to record the user’s inactivity time on the app and then take any action upon it if required.It can be useful in some other situations also −Prevent sending the network request if the page is not being used by the user as this would reduce the traffic on the server.Also, this would really help in saving the cost of the servers.This is used while monitoring the time spent by each user and then ... Read More

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

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

370 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

785 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 26-Apr-2022 12:25:42

2K+ Views

There are multiple ways of removing duplicate elements from an array in JavaScript. In this article, we are going to explore some of the top methods to remove duplicate elements.Using the filter() MethodThe filter() method creates a new array of elements with the passed condition. This will only contain the element that returns true as part of this filter method. So to achieve the removal of the duplicate elements we just need to add the condition in the filter() method and it will do the rest of the work.# filter.js    var arr = ["steve", "mark", "mark", "bill", "steve", " ... Read More

How to Toggle Password Visibility in JavaScript?

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

469 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

How to Ping a Server using JavaScript?

Mayank Agarwal
Updated on 27-Apr-2022 09:47:12

7K+ Views

A server ping can be defined as hitting a server and getting a response in return from that server. The idea is to send an echo message that will keep the health check and check whether the server is up and running or not. On sending a PING every server sends a PONG that shows that the server is active. Ping messages are sent by the ICMP (Internet Control Messaging Protocol). The lower the ping time the stronger the connection between the host and the server.ApproachWe can use a JavaScript function for sending the Ping messages to the server. In ... Read More

JavaScript: How to map array values without using "map" method?

Mayank Agarwal
Updated on 26-Apr-2022 11:19:02

1K+ Views

We can map the elements of an array by using the looping methods in JavaScript. The map() method creates a new array that will produce the outputs of a function for each element of the array. The map method can also be implemented using the for loop in JavaScript.ApproachWe will create two arrays out of which the first array contains the array elements that need to be mapped whereas the second array contains the output of the following array. We will be using the JavaScript Array push() function for returning the values of a function in the output array.Syntaxarray.push(element1, element2, ... Read More

Advertisements