what is map js code example
Example 1: javascript map
array.map((item) => {
return item * 2
}
Example 2: javascript map
function listFruits() {
let fruits = ["apple", "cherry", "pear"]
fruits.map((fruit, index) => {
console.log(index, fruit)
})
}
listFruits()
Example 3: map javascript
function each(collection, action) {
if (Array.isArray(collection)) {
for (var i = 0; i < collection.length; i++) {
action(collection[i], i, collection);
}
} else {
for (var key in collection) {
action(collection[key], key, collection);
}
}
}
Example 4: map in javascript
['elem', 'another', 'name'].map((value, index, originalArray) => {
console.log(.....)
});