Found 8894 Articles for Front End Technology

How to use the "in" operator in JavaScript?

Mayank Agarwal
Updated on 28-Apr-2022 11:59:56

139 Views

In this article, we are going to explore the 'in' operator and how to use it in JavaScript. The in operator is an inbuilt operator in JavaScript that is used for checking whether a particular property exists in an object or not. It will return true if the property exists, else false is returned.Syntaxprop in objectParametersThis function accepts the following parameters as described below −prop − This parameter holds the string or symbol that represents a property name or the array index.object − This object will be checked if it contains the prop or not.Return value − This method will ... Read More

How to use Static Variables in JavaScript?

Mayank Agarwal
Updated on 28-Apr-2022 11:55:16

3K+ Views

The keyword "Static" is used for defining a static method or a static property of a class. The benefit of a static method is that we do not need to create an instance or object of the class. It does not have multiple values. It will have a single static value defined during initialization.The keyword static is similar to the const keyword. It is set at the run time when the initialization takes place and these types of variables have global presence and scope. We can use these static variables anywhere over the script.Note − We can reassign and change ... Read More

How to transform JSON text into a JavaScript object?

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

1K+ 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

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

466 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

982 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

371 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

787 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

Advertisements