new Map() in javascript 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: how to use the map method in javascript
const numbers = [1, 2, 3, 4, 5];
const bigNumbers = numbers.map(number => {
return number * 10;
});
Example 4: initialize a map js
let map = new Map()
map['bla'] = 'blaa'
map['bla2'] = 'blaaa2'
console.log(map)
Example 5: map in javascript
const arr = [1,2,3,4]
const sqrs = arr.map((num) => num ** 2)
console.log(sqrs)
console.log(arr)