Found 10483 Articles for Web Development

How to shuffle an array in a random manner in JavaScript?

Aman Kumar
Updated on 06-Dec-2022 06:05:44

450 Views

Shuffle means you are rearranging something from the elements of your array or mixing it to produce a random order. The _.shuffle() belongs to underscore.js a JavaScript library that provides versatile functions. It is used to arrange the list of array elements in a random manner it uses Fisher-Yates shuffle Algorithm. So every time you execute your code this will gives outputs in a different order according to the Fisher-Yates shuffle Algorithm. Following is an example of the _.shuffle() function − _.shuffle(list) Parameters − This function accepts the single arguments list. the argument is used to hold the list of ... Read More

How to find the common elements between two or more arrays in JavaScript?

Nikhilesh Aleti
Updated on 19-Sep-2022 08:13:58

10K+ Views

Arrays is typeof operator in JavaScript. Arrays can access its elements with the help of index numbers which starts with 0. Let array = [“India”, “Australia”, “USA”]; There are enough number of ways to get the common elements from the arrays. Now, In this below scenario we use for loop for finding common arrays. In this article, we are going to discuss how to find the common elements between two or more arrays in JavaScript. Using for loop One way to find the common elements between two or more arrays is using the simple for loop. Following are the ... Read More

How to remove the 0th indexed element in an array and return the rest of the elements in JavaScript?

Nikhilesh Aleti
Updated on 19-Sep-2022 09:03:41

821 Views

Array is a structure, which can hold values elements and they can be accessed by referencing to them with the help of index numbers. Const colors = [“Green”, “Maroon”, “Blue”]; Reference index of array In JavaScript arrays are referred with reference indexes. These indexes are zero-indexed. The very first element in the array will be 0 index. Second element will be index 1. Last element in the array will be the total size of the array minus 1. Spread operator (…) In this article, we are going to discuss how to remove the 0th indexed element in an ... Read More

How to remove event handlers in JavaScript?

Nikhilesh Aleti
Updated on 25-Oct-2023 13:59:39

30K+ Views

An event is defined as a change in an object's state. There are a number of events in HTML that show when a user or browser performs a certain action. JavaScript responds to these events when JavaScript code is embedded in HTML and allows execution. The process of responding to events is known as event handling. As a result, JavaScript uses event handlers to handle HTML events. In this article, we are going to discuss how to remove event handlers in JavaScript. Here, we use the removeEventListener() method to remove an event handler from an element in JavaScript. Using the ... Read More

How to add an event handler to the specified element in JavaScript?

Nikhilesh Aleti
Updated on 19-Sep-2022 07:26:19

320 Views

Events in HTML are “things” that take place using HTML elements. JavaScript can “respond” to these events when used in HTML pages. Events are produced as a result of user interaction with the elements of the user interface. The actions that trigger an event include, for instance, pressing a button, moving the mouse, typing a character on the keyboard, choosing an item from a list, and scrolling the page. Examples of HTML events are mentioned below − An HTML web page has finished loading An HTML input field was changed An HTML button was clicked Adding an event ... Read More

How to convert a string to a floating point number in JavaScript?

Nikhilesh Aleti
Updated on 19-Sep-2022 08:46:33

1K+ Views

In this article, we are going to discuss how to convert a string to a floating-point number in JavaScript. We can convert a string to a floating point in three ways − Using the parseFloat() method. Using the parseInt() method. Using type conversion. Using the parseFloat() method The parseFloat() is a function in JavaScript, this accept the string as input and convert the value into a floating point number. Let’s consider a scenario where there is numeral value in the string and also if the first character of the string is not a number then the resultant output ... Read More

How to check whether provided elements in an array have passed a specified condition or not in JavaScript?

Nikhilesh Aleti
Updated on 19-Sep-2022 08:00:52

181 Views

In this article, we are going to discuss whether provided elements in an array have passed a specified condition or not in JavaScript. Here, we can use the _.filter() method, every() method, some() method, filter() method, and for loop. They return true if every element in an array has met the condition, otherwise, they return false. Using the Array.filter() method This Array.filter() method is a JavaScript function. Array.filter() method will be creating a new array containing the elements that are passed in the condition which is defined by function in program. This Array.filter() method will not execute if elements are ... Read More

How to compare two objects in JavaScript?

Nikhilesh Aleti
Updated on 13-Sep-2023 15:50:19

24K+ Views

Objects in JavaScript is an entity, where it consists of properties and type. Let’s consider sports as an object, in Car the properties can be color, price, height, width, etc. Exactly the same also happens in JavaScript, which has objects and contains properties to them. Const car = { color : 'Black', price : 2500000, height : '6 feet', width : '5 feet' } The equality operator (===) verifies whether the two operands are equal or not and returns a Boolean value. If the both operands are ... Read More

How to clone an array using spread operator in JavaScript?

Nikhilesh Aleti
Updated on 16-Sep-2022 13:15:10

3K+ Views

In this article, we are going to discuss how to use the spread operator to clone an array in JavaScript. Cloning is just the process of copying one array into another array. Previously, the slice() method was used to clone an array, however, ES6 now provides the spread operator(...) to simply clone an array. Before proceeding further let us look at the definitions of array and spread operator. Array An Array is usually a data structure, in JavaScript it is an object which can hold multiple values at once. For example, Below “Arr” is an array. Const Arr = [‘Tutorials’, ... Read More

How to select a radio button by default in JavaScript?

Nikhilesh Aleti
Updated on 19-Sep-2022 07:57:16

14K+ Views

Radio button A radio button is used to select one among many options. This is one of the element in HTML. This radio button is a radio group to show a set of multiple choices, and in that only one can be selected. This way far similar to checkboxes, in checkboxes scenario’s we can select either one or many options as we can, whereas in radio button it can’t be done selecting multiple choices. We can define radio button is HTML using tag. Following is the syntax to define radio buttons in HTML Example 1 None selected ... Read More

Advertisements