Front End Technology Articles - Page 577 of 860

How to use spread operator to join two or more arrays in JavaScript?

Nikhilesh Aleti
Updated on 16-Sep-2022 14:39:58

8K+ Views

Array is a variable. Which has an ability to store multiple values in it using appropriate syntax. Every value is referred with index numbers which will start from 0. Const ipl = [“Chennai”, “Mumbai”, Hyderabad”]; Spread operator (…) Spread operator can do the copying of one object or array’s properties and values to another object or array. This will be a shallow copy of the original. Const ipl = [“Chennai”, “Mumbai”, Hyderabad”]; Spread operator can do the copying of one object or array’s properties and values to another object or array. This will be a shallow copy of ... Read More

How to find maximum value in an array using spread operator in JavaScript?

Nikhilesh Aleti
Updated on 16-Sep-2022 13:22:49

1K+ Views

In this article, we are going to discuss how to find the maximum value in an array using the spread operator in JavaScript. For this you need to understand what is an array, what is spread operator and Math.max() method. Array An Array is a variable which is used to store different types of elements. Used to store a bunch of elements and access them with a single variable. Declaration of array can be done in below methods. var House = [ ]; // method 1 var House = new Array(); // method 2 Spread operator (…) This ... Read More

How to pass arrays as function arguments in JavaScript?

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

4K+ Views

Passing arrays as function argumentsIn olden days if we need to pass arrays as function arguments then apply() and null should be used. The use of null makes a code unclean. So to make code clean and also to pass an array as a function argument, the spread operator comes in to picture. By using the spread operator we don't need to use apply() function. Lets' discuss it in a nutshell.ExampleIn the following example, we have used null and apply() to pass an array as a function argument. This is an obsolete method. This method is replaced by a modern method in ... Read More

Can re-declaring a variable destroy the value of that variable in JavaScript?

vineeth.mariserla
Updated on 29-Jun-2020 12:47:46

351 Views

Re-declaring a variable will not destroy the value of a variable, until and unless it is assigned with some other new value.If we look at the following example variables "x" and ''y'' were assigned with values 4 and 8 respectively, later on when those variables were reassigned, the old values were replaced with the new values and displayed as shown in the output.ExampleLive Demo           var x = new Number(4);       var x = 7;       var y = 8;       var y = 10;       document.write(x);     ... Read More

How to hide/show HTML elements in JavaScript?

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

2K+ Views

Using Css style we can hide or show HTML elements in javascript. Css provides properties such as block and none to hide/show the HTML elements.Hiding an elementExampleIn the following example when the "Hideme" button has clicked the text in the paragraph tag has been disappeared as shown in the output.Live Demo    Using JavaScript to hide HTML elements.    

How to find duplicates in an array using set() and filter() methods in JavaScript?

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

1K+ Views

Removing duplicatesTo remove duplicates in an array we have many logical methods, but advanced javascript has provided some methods so that the task of removing duplicates has become very simple. Some of those methods are set() and filter(). For better understanding lets' discuss each method individually.Set()The important use of the set() method is that it only allows unique values. In other words, it will automatically remove duplicates and makes the task easy for us. The Set() method won't take any logical approach in removing duplicates.Example In the following example, the duplicates in the provided array have been removed without any ... Read More

How to convert a string in to a function in JavaScript?

vineeth.mariserla
Updated on 29-Jun-2020 11:57:31

6K+ Views

To convert a string in to function "eval()" method should be used. This method takes a string as a parameter and converts it into a function.syntaxeval(string);ExampleIn the following example, in a string itself, a property called 'age' is assigned with a function. Later on, using eval() function the property age is converted into a function and displayed as shown in the output. Live Demo    var string = '{"name":"Ram", "age":"function() {return 27;}", "city":"New jersey"}';    var fun = JSON.parse(string);    fun.age = eval("(" + fun.age + ")");    document.write(fun.name + " "+ "of Age" + " "+ fun.age()+ " " + "from ... Read More

How to convert a string in to date object in JavaScript?

vineeth.mariserla
Updated on 29-Jun-2020 11:48:18

347 Views

To convert a string in to date object Date() method should be used. This method creates a date instance that represents a single moment in time in a platform-independent format.ExampleIn the following example a string named "str" is initially parsed using JSON.parse() method and then converted in to date object using Date() method.Live Demo     var str = '{"name":"Ram", "DOB":"1980-11-1", "country":"India"}';    var dateObj = JSON.parse(str);    dateObj.DOB = new Date(dateObj.DOB);    document.write(dateObj.DOB); OutputThu Nov 01 0198 00:00:00 GMT+0553 (India Standard Time)

How to delete a property of an object in JavaScript?

vineeth.mariserla
Updated on 29-Jun-2020 11:49:20

404 Views

To delete a property of an object, delete key word should be used. Delete key word can be used with both the methods such as Dot method and Bracket method.syntaxdelete object.property;ExampleIn the following example initially when the property "country" is executed its value "England" is displayed in the output. But when that property is deleted using delete keyword, instead of "England", undefined is displayed as shown in the output.Live Demo    var txt = "";    var person = {       "name":"Ram",       "age":27,       "address": {          "houseno" : 123,   ... Read More

How to modify properties of a nested object in JavaScript?

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

3K+ Views

There are two methods to modify properties of nested objects. One is Dot method and the other is Bracket method. The functionality is same for both the methods, but the only difference is their notation. lets' discuss them in detail.Dot methodExampleIn the following example initially the value of property country is England. But using Dot notation the value is changed to India.Live Demo    var person;    var txt = '';    person = {       "name":"Ram",       "age":27,       "address": {          "houseno":123,          "streetname":"Baker street",     ... Read More

Advertisements