This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cityNames = ['Mumbai', 'Delhi', 'Pune', 'Ahmadabad', 'Indore']; | |
console.log(...cityNames); // Mumbai Delhi Pune Ahmadabad Indore | |
var numbers = [22, 11, 98, 43, 87, 56, 45, 01, 24]; | |
// Without spread operator | |
console.log("Smallest no.:",Math.min(numbers)); // Smallest no.: NaN | |
// With spread operator | |
console.log("Smallest no.:",Math.min(...numbers)); // Smallest no.: 1 | |
// copy an array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var empEligibilityDetails = [ | |
{ | |
"name": "Vishal", | |
"age": 30, | |
"isManager": false, | |
"city": "Mumbai" | |
}, | |
{ | |
"name": "Kunal", | |
"age": 31, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//splice() demo program | |
var cityNames = ['Mumbai', 'Delhi', 'Pune', 'Ahmadabad', 'Indore']; | |
console.log("City names:", cityNames); | |
// Output : City names: [ 'Mumbai', 'Delhi', 'Pune', 'Ahmadabad', 'Indore' ] | |
cityNames.splice(1); // if delete count is omitted, from startIndex, all items will be deleted | |
console.log(cityNames); //[ 'Mumbai' ] | |
//Add new elements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//slice() example | |
var cityNames = ['Mumbai', 'Delhi', 'Pune', 'Ahmadabad', 'Indore']; | |
console.log("City names:", cityNames); | |
// Output : City names: [ 'Mumbai', 'Delhi', 'Pune', 'Ahmadabad', 'Indore' ] | |
var newCities = cityNames.slice(); // gets all - shallow copy | |
console.log(newCities); //[ 'Mumbai', 'Delhi', 'Pune', 'Ahmadabad', 'Indore' ] | |
var newTwoCities = cityNames.slice(1, 3); // start from 1st index and before 3rd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Basic array | |
var cityNames = ['Mumbai', 'Delhi', 'Pune', 'Ahmadabad', 'Indore']; | |
console.log("City names:", cityNames); | |
// Output : City names: [ 'Mumbai', 'Delhi', 'Pune', 'Ahmadabad', 'Indore' ] | |
console.log("City at 2nd index:", cityNames[2]); | |
//Add an item to an array | |
cityNames.push('Jaipur'); | |
console.log("City names:", cityNames); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var colorCodeData = [ | |
{color: "red", value: "#f00"}, | |
{color: "green", value: "#0f0"}, | |
{color: "blue", value: "#00f"}, | |
{color: "cyan", value: "#0ff"}, | |
{color: "magenta", value: "#f0f"}, | |
{color: "yellow", value: "#ff0"}, | |
{color: "black", value: "#000"} | |
] |