Change Object Key Without Modifying Original Array in JavaScript

AmitDiwan
Updated on 18-Jul-2020 09:09:12

476 Views

Following is the code to change an object key without changing the original array in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    } Change an object Key without changing the original array CLICK HERE Click the above button to change the name object key to fullName    let BtnEle = document.querySelector(".Btn");    let resEle = document.querySelector(".result");    let sampleEle = document.querySelector(".sample");    let obj = [       { name: "Rohan Sharma", age: 12 },     ... Read More

Joining a JavaScript Array with a Condition

AmitDiwan
Updated on 18-Jul-2020 09:06:07

629 Views

Following is the code to a JavaScript array with a condition in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .result {       color: red;    } Joining a JavaScript array with a condition CLICK HERE Click the above button to join the array elements that are divisible by 2.    let BtnEle = ... Read More

Join Two Arrays in JavaScript

AmitDiwan
Updated on 18-Jul-2020 09:03:20

262 Views

Following is the code to join two arrays together in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .result {       color: red;    } Join two arrays in JavaScript CLICK HERE Click the above button to join the above two arrays together.    let BtnEle = document.querySelector(".Btn");    let resEle = document.querySelector(".result");   ... Read More

Merge Two JavaScript Objects

AmitDiwan
Updated on 18-Jul-2020 08:59:49

479 Views

Following is the code to merge two JavaScript objects together −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Merge two JavaScript objects CLICK HERE Click the above button to merge person and adress object together.    let BtnEle = document.querySelector(".Btn");    let resEle = document.querySelector(".result");    let person = {       name: "Rohan",       age: 22,    };    let address = {       state: "Delhi",       country: "India",    };    let mergedObj = { ...person, ...address };    BtnEle.addEventListener("click", () => {       for (let i in mergedObj) {          resEle.innerHTML += "Key = " + i + " : Value = " + mergedObj[i] + "";       }    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Replacing Property Names in JavaScript Objects

AmitDiwan
Updated on 18-Jul-2020 08:57:43

407 Views

Following is the code to replace array of object property name in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Replacing array of object property name CLICK HERE Click the above button to change the property name of an object in array    let BtnEle = document.querySelector(".Btn");    let resEle = document.querySelector(".result");    var person = [     ... Read More

Find Elements of JavaScript Array by Multiple Values

AmitDiwan
Updated on 18-Jul-2020 08:55:14

292 Views

Following is the code to find elements of JavaScript array by multiple values −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Find elements of JavaScript array by multiple values CLICK HERE Click the above button to see if arr contains all elements of arr1 or not    let BtnEle = document.querySelector(".Btn");    let resEle = document.querySelector(".result");    let arr = ... Read More

Convert Array of Comma-Separated Strings to Array of Objects

AmitDiwan
Updated on 18-Jul-2020 08:53:17

355 Views

Following is the code to convert array of comma separated strings to array of objects −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .result {       color: red;    } Convert array of comma separated strings to array of object CLICK HERE Click the above button to convert the above array of strings to objects ... Read More

Convert a String to JavaScript Object

AmitDiwan
Updated on 18-Jul-2020 08:50:26

546 Views

Following is the code to convert a string to JavaScript object −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 18px;       font-weight: 500;       color: red;    } convert a string to JavaScript object {"name":"Rohan", "sports":["Cricket", "Football"], "country":"India"} CLICK HERE Click on the above button to convert the above string to JavaScript object    let sampleEle = document.querySelector(".sample");    let resultEle = document.querySelector(".result");    let parsedJson = ... Read More

Explain Equality of Objects in JavaScript

AmitDiwan
Updated on 18-Jul-2020 08:48:11

157 Views

In JavaScript the primitive like string, number, boolean etc are compared by their values while objects (native or custom) are compared by their reference. Comparing by reference means whether the two or more object point to same location in memory or not.Following is the code to explain equality of objects in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Equality of ... Read More

Parse String from a JavaScript Array

AmitDiwan
Updated on 18-Jul-2020 08:43:44

220 Views

Following is the code to parse a string from a JavaScript array −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Parse a string from a JavaScript array CLICK HERE Click the above button to convert the array arr to string    let BtnEle = document.querySelector(".Btn");    let resEle = document.querySelector(".result");    let arr = ["Cow", "Lion", "Tiger", "Dog", "Cat"];    BtnEle.addEventListener("click", () => {       resEle.innerHTML = arr.toString();    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Advertisements