Found 6710 Articles for Javascript

Object de-structuring in JavaScript.

AmitDiwan
Updated on 16-Jul-2020 08:57:01

124 Views

Following is the code for object de-structuring in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample, .result {       font-size: 18px;       font-weight: 500;       color: red;    }    .result {       color: rebeccapurple;    } Object de-structuring in JavaScript. CLICK HERE Click on the above button to destructure the object above    let sampleEle = document.querySelector(".sample");    let resultEle = document.querySelector(".result");    let obj = { ... Read More

Array.prototype.sort() in JavaScript.

AmitDiwan
Updated on 16-Jul-2020 08:52:17

170 Views

The JavaScript Array.prototype.sort() method is used for sorting an array. The order of sorting can be alphabetic, numeric, ascending or descending.Following is the code for the Array.prototype.sort() method −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample, .result {       font-size: 18px;       font-weight: 500;       color: red;    }    .result {       color: rebeccapurple;    } JavaScript Array.prototype.sort() method CLICK HERE Click on the above button to sort the ... Read More

Array.prototype.flat() in JavaScript.

AmitDiwan
Updated on 16-Jul-2020 08:47:46

130 Views

The JavaScript Array.prototype.flat() method is used to flatten an array recursively up to a specified depth. It doesn’t manipulate the original array but creates a new flattened array.Following is the code for the Array.prototype.flat() method −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,.sample {       font-size: 20px;       font-weight: 500;    } Array.prototype.flat() method {       let store = arr.flat(1);       store.forEach((item,index) => {          resEle.innerHTML += index + ' : ' + item + '';       });    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Array.prototype.flatMap() in JavaScript.

AmitDiwan
Updated on 16-Jul-2020 08:45:19

140 Views

The JavaScript Array.prototype.flatMap() function flattens the given nested array into a new flat array.Following is the code for the Array.prototype, flatMap() method −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 20px;       font-weight: 500;    } JavaScript Array flatMap() CLICK HERE Click on the above button to convert the nested array to flat array    let fillEle = document.querySelector(".sample");    let arr = ["cow", ["bull", "lion", "tiger"], "sheep"];    for (x ... Read More

Explain Optional Catch Binding in JavaScript.

AmitDiwan
Updated on 16-Jul-2020 08:41:45

440 Views

The optional catch binding introduced in ES2019 allows us to remove the surrounding parentheses of a catch binding i.e. we don’t need to use a variable to store the error object. It is useful especially if we know about the error in advance or even if want to react to an error without knowing about it.Following is the code for the optional catch binding in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       ... Read More

Explain String.trimStart() & String.trimEnd() methods in JavaScript

AmitDiwan
Updated on 16-Jul-2020 08:38:55

493 Views

The String.trimStart() method is used to remove whitespace from the string beginning while the String.trimEnd() method removes whitespace from the end of the string.Following is the code for the String.trimStart() and String.trimEnd() methods −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,.sample {       font-size: 20px;       font-weight: 500;    } String.trimStart() and String.trimEnd() methods {       resEle.innerHTML = "trimStart() :" + str.trimStart() + "|";       resEle.innerHTML += "trimEnd() :" + str.trimEnd() + "|";    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Object.fromEntries() method in JavaScript.

AmitDiwan
Updated on 16-Jul-2020 08:36:28

162 Views

The Object.fromEntries() method in JavaScript is used for converting an iterable like an array, map having a key value pair into an object.Following is the code for the Object.fromEntries() method −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;    } Object.fromEntries() method [[firstName, Rohan], [lastName, Sharma], [age, 22]] Object = CLICK HERE Click on the above button to convert the above array into object   ... Read More

array.flatmap() method in JavaScript.

AmitDiwan
Updated on 16-Jul-2020 08:33:50

115 Views

The JavaScript array.flatMap() function flattens the given nested array into a new flat array.Following is the code for the array.flatMap() method −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 20px;       font-weight: 500;    } JavaScript Array flatMap() CLICK HERE Click on the above button to convert the nested array to flat array    let fillEle = document.querySelector(".sample");    let arr = ["cow", ["bull", "lion", "tiger"], "sheep"];    for ... Read More

Array.flat() method in JavaScript.

AmitDiwan
Updated on 16-Jul-2020 08:28:19

183 Views

The JavaScript Array.flat() method is used to flatten an array recursively up to a specified depth. It doesn’t manipulate the original array but creates a new flattened array.Following is the code for the Array.flat() method −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;    } Array.flat() method [1, 2, 3, [4, 5], [6, [7, 8]]] After flat : CLICK HERE Click on the above button to ... Read More

Array.prototype.includes() method in JavaScript.

AmitDiwan
Updated on 16-Jul-2020 08:22:13

187 Views

The JavaScript Array.protoype.includes() method is used to check if an array contains a given element or not.Following is the code for the Array.protoype.includes() method −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 20px;       font-weight: 500;    } JavaScript Array includes() CLICK HERE Click on the above button to check if the array contains lion element or not    let fillEle = document.querySelector(".sample");    let arr = ["cow", "bull", "lion", "tiger", ... Read More

Advertisements