Found 8862 Articles for Front End Technology

How to get the values of an object in JavaScript?

Aman Kumar
Updated on 06-Dec-2022 07:21:21

491 Views

There are some methods for finding the value of an object which is an object.values(), but when you are using this method the process will be lengthy. We can find easily the value of an object with the help of the _.values() function it is a built-in method that belongs to underscore.js a javascript library that provides versatile functions. _.value() this method requires no for loop to execute the values, it is a direct method to find the value of the object. Syntax _.values( object ) Parameters − This function accepts only one argument which is an object. An object ... Read More

How to invert an object in JavaScript?

Aman Kumar
Updated on 06-Dec-2022 07:14:59

2K+ Views

Invert means to print the value in reverse order. In a technical word, we can say that suppose we have taken an object of the array. The object takes the value in key-value pairs and prints the value in value-key pairs. The _.invert() function belongs to the underscore.js a javascript library that provides versatile functions. This is used to copy an object where the object key is converted into value and the object is converted into the key. This means the [key, value] of the object is reversed. Syntax Following is the syntax of the _.invert() function − _.invert(object) ... Read More

How to get the first n values of an array in JavaScript?

Aman Kumar
Updated on 06-Dec-2022 07:05:20

921 Views

In this article we are going to discuss how to get the first n values of an array using JavaScript. First, n value − to find the elements from the first index to n (n is the given number or given index) suppose you have given the n value as 5 the returned elements will be from index 0 to 5. Using the _.first() function To get the first n elements of an array we have many logical methods. But underscore.js provides the _.first() function. Which will directly or in a simple way gives the output. Note − if we did not mention ... Read More

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

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

348 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

What is the importance of _.union() method in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

1K+ Views

_.union()_.Union() method belongs to underscore.js a library of javascript. The _.union() function is used to take n number of arrays and return a new array with the unique terms in all those arrays (union of all array). It scrutinizes each and every value of the arrays and pushes out unique values into another array.syntax_.union( array1, array2, .... );ExampleIn the following example, _.union() is used to get an array of unique elements.Live Demo document.write(_.union([1, 2, 9, 40], ... 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

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

603 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

What is the importance of _.initial() function in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

365 Views

_.initial()_.initial() is a function in underscore.js, which is a library of javascript. This method is used to differentiate the last element of an array from the rest of the elements. This method just ignores the last value of an array.syntax_.initial( array, n );_.Initial() can take 2 parameters. array - The method takes the array and gives out all the elements except the last element.n - It is nothing but a number of elements that are to be trimmed from the given array. It is optional.ExampleLive Demo document.write(_.initial([1, 2, 3, 4, 5])); Output1, ... Read More

What is the use of _.size() method in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

551 Views

_.size()_.Size() is from the underscore.js library of javascript. This is used to find the size of an array. One should make sure that before using this method one should use the CDN of the underscore.js to execute the code.syntax_.size(array);Example-1In the following example, a normal array is passed into _.size() method to get the size of the array.Live Demo var arr = [100, 62, 73, 534, 565]; document.write(_.size(arr)); Output5Example-2In the following example, an array that consists of object elements is sent into _.size() method to find the size.Live Demo ... Read More

What is the use of Math.hypot() function in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

152 Views

Math.hypot()Math.Hypot() method is used to find the square root of the sum of the squares of the elements that are passed to it as arguments. This method is actually used to find the hypotenuse of a right-angle triangle whose sides are passed as arguments into it. syntaxMath.hypot(arg1, arg2, ....);ExampleIn the following example, sides of a right-angle triangle are passed to find the hypotenuse. If any value is can't be converted to a number then NaN will be displayed as output. Live Demo document.write(Math.hypot(7, 24)); document.write(""); document.write(Math.hypot(7, "hi")); Output25 NaNThis ... Read More

Advertisements