map javascrip code example
Example 1: javascript map array
const myArray = ['Sam', 'Alice', 'Nick', 'Matt'];
const newArray = myArray.map(name => {
return 'My name is ' + name;
});
console.log(newArray);
const anotherArray = myArray.map((value, index) => index + ": " + value);
console.log(anotherArray);
console.log(myArray);
Example 2: javascript map
array.map((item) => {
return item * 2
}
Example 3: map in js
const data = {name: "laptop", brands: ["dell", "acer", "asus"]}
let inside_data = data.brands.map((i) => {
console.log(i);
});
Example 4: javascript map
The map() method creates a new array with the results of calling a provided function on every element in the calling array.
Example 5: javascript map
var newArray = unchangedArray.map(function(item, index){
return item;
});
var newArray = unchangedArray.map((item, index) => item);