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
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
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
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
Const and let were introduced in ES2015 to declare block scoped variables. While variables declared using let can be reassigned, they cannot be reassigned if they were declared using const.Following is the code showing let and const in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 20px; font-weight: 500; } Const and let in JavaScript CLICK HERE Click on the above button to reassign const and let ... Read More
To declare block scoped variables, we use the keyword let and const introduced in ES2015.Following is the code showing declaring black scoped variables in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 20px; font-weight: 500; } Declaring block scoped variables CLICK HERE Click on the above button to declare and display block scoped variables let resEle = document.querySelector(".result"); let sampleEle = document.querySelector(".sample");{ ... Read More
Following is the code for removing elements using splice() method in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample,.result { font-size: 20px; font-weight: 500; } Remove elements using splice() CLICK HERE Click on the above button to remove elements between 1st and 5th element let fillEle = document.querySelector(".sample"); let resEle = document.querySelector(".result"); let arr = [1, 3, 5, 7, 9, 11]; fillEle.innerHTML = arr; document.querySelector(".Btn").addEventListener("click", () => { arr.splice(1, 4); resEle.innerHTML = "Spliced array = " + arr; }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −
The Array.prototype.find() method returns the first element value that satisfy a given condition in an array.Following is the code for the Array.prototype.find() method −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .find { font-size: 20px; font-weight: 500; } JavaScript Array Find() example CLICK HERE Click on the above button to find lion among the animals function findLion(animal) { return animal === "lion"; } let fillEle = ... Read More
The error object is basically thrown by the JavaScript interpreter when a script error occurs. This error object can also be thrown as exception for user defined exceptions. The two javaScript error object properties are −PropertyDescriptionnameIt sets or returns the name of the error.messageIt sets or returns the error message as stringFollowing is the code for error object in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; } ... Read More
Block scope is an area between two { curly braces } which can be between loops, if condition or switch statement. The let and const introduced in ES2015 allow us to create block scoped variables that can be accessed only inside those block.Following is the code showing block scoping in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result{ font-size: 20px; font-weight: 500; } Block scoping in JavaScript CLICK HERE Click on ... Read More
 
 Data Structure
 Data Structure Networking
 Networking RDBMS
 RDBMS Operating System
 Operating System Java
 Java MS Excel
 MS Excel iOS
 iOS HTML
 HTML CSS
 CSS Android
 Android Python
 Python C Programming
 C Programming C++
 C++ C#
 C# MongoDB
 MongoDB MySQL
 MySQL Javascript
 Javascript PHP
 PHP