array map index code example
Example 1: es6 map usin index
const array = [1, 2, 3, 4];
const map = array.map((x, index) => {
console.log(index);
return x + index;
});
console.log(map);
Example 2: 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 3: map javascript index
map((element) => { ... } )
map((element, index) => { ... } )
map((element, index, array) => { ... } )
map(callbackFn)
map(callbackFn, thisArg)
map(function callbackFn(element) { ... })
map(function callbackFn(element, index) { ... })
map(function callbackFn(element, index, array){ ... })
map(function callbackFn(element, index, array) { ... }, thisArg)
Example 4: map index
array.map((currentelement, index) => {
});
Example 5: javascript map
function listFruits() {
let fruits = ["apple", "cherry", "pear"]
fruits.map((fruit, index) => {
console.log(index, fruit)
})
}
listFruits()
Example 6: js array map
const array1 = [1, 4, 9, 16];
const map1 = array1.map(x => x * 2);
console.log(map1);