Front End Technology Articles - Page 574 of 860

What is the importance of '+' operator in type conversion in JavaScript?

Aman Kumar
Updated on 06-Dec-2022 07:48:50

248 Views

Java script is an autonomous type of language most of the time operation directly convert the value of their write type. But there are also cases in which we need to do explicit type conversion.While Java script provides many ways to convert data from one form to another. But there are two most common types of conversion. converting the value to a string. converting a value to a number. Implicit conversion There are various operators and functions in the JavaScript that automatically convert values to the right type like the alert() function in JavaScript accepts any value and ... Read More

How to remove the last digit of a number and execute the remaining digits in JavaScript?

vineeth.mariserla
Updated on 06-Dec-2022 07:44:55

5K+ Views

In this article we are going to discuss how to remove the last digit of a number and execute the remaining digits using JavaScript.A number firstly should be converted into the string after that you perform your operation like the length of the string − 1 after the removed the last element and execute the remaining part. Here type conversion is needed because we are changing the number to a string. Syntax Following is the syntax of the substring() method − str.substring(0, str.length - 1) This method accepts two parameters as an argument first is the string index from where you ... Read More

What is the relation between 'null' and '0' in JavaScript?

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

4K+ Views

It looks very odd to hear that because in mathematics if we have two numbers i.e a and b and if a is not less than b then the possible scenarios are either a is greater than or equal to b. But in the case of null and “0” null is not greater than "0" or equal to "0" but greater than or equal to "0". (null>=0) In JavaScript "0" is equal to false because "0" is a type of string when it is tested for equality the automatic type conversion of JavaScript will come into effect and convert the ... Read More

How to shallow copy the objects in JavaScript?

Aman Kumar
Updated on 06-Dec-2022 12:41:43

449 Views

In this article we are going to discuss how to perform shallow copy on JavaScript objects. If the source value is the reference to an object, then it will only copy the reference value into the target value. When the source properties are copied without reference and there exists a source property whose value is an object and is copied as a reference. A shallow copy constructs a new compound object and then (to the extent possible) inserts references into the objects found in the original. Using the _.extend() method Underscore.js are a library of JavaScript and has a method ... Read More

How to get the values of an object in JavaScript?

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

647 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

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

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

472 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

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

Advertisements