xxxxxxxxxx
// object.fromEntries Explain
// Note : it's work with array of an array
let name =['noor','alex','biker','hosler']
let ages = [ 11 , 13 , 15 , 17];
const newvalue=(
name.map((nameArrayElement,index)=>{
return [nameArrayElement,ages[index]]
})
)
console.log(newvalue);
// output without using fromEntries
// [ [ 'noor', 11 ], [ 'alex', 13 ], [ 'biker', 15 ], [ 'hosler', 17 ] ]
const newvalueAfterFromEntries=Object.fromEntries(
name.map((nameArrayElement,index)=>{
return [nameArrayElement,ages[index]]
})
)
console.log(newvalueAfterFromEntries);
// Output AfterFromEntries
// { noor: 11, alex: 13, biker: 15, hosler: 17 }
// By Noor Mohammad Patwary
xxxxxxxxxx
// One array key as another array's value
const FRUITS = ["Banana", "Orange", "Dragon", "Apple", "Weed"];
let colors=[ 'yellow ', 'OrangeColor', 'Merun', 'Green', 'Nice', ];
let result=Object.fromEntries(
FRUITS.map((array1Value,indexNumber)=>{
return [array1Value,colors[indexNumber]];
})
);
console.log(result);
// output
// {
// Banana: 'yellow ',
// Orange: 'OrangeColor',
// Dragon: 'Merun',
// Apple: 'Green',
// Weed: 'Nice'
// }
xxxxxxxxxx
/* Copying arrays or parts of arrays in JavaScript */
var fruit = ["apple", "banana", "fig"]; // Define initial array.
console.log(fruit); // ["apple", "banana", "fig"]
// Copy an entire array using .slice()
var fruit2 = fruit.slice();
console.log(fruit2); // ["apple", "banana", "fig"]
// Copy only two array indicies rather than all three
// From index 0 (inclusive) to index 2 (noninclusive)
var fruit3 = fruit.slice(0,2);
console.log(fruit3); // ["apple", "banana"]
xxxxxxxxxx
var ar = ["apple","banana","canaple"];
var bar = Array.from(ar);
alert(bar[1]); // alerts 'banana'
// Notes: this is for in In ES6, works for an object of arrays too!