how to create a map in javascript code example
Example 1: how to use the map method in javascript
const numbers = [1, 2, 3, 4, 5];
const bigNumbers = numbers.map(number => {
return number * 10;
});
Example 2: map in js
const data = {name: "laptop", brands: ["dell", "acer", "asus"]}
let inside_data = data.brands.map((i) => {
console.log(i);
});
Example 3: map in javascript
let myMap = new Map()
let keyString = 'a string'
let keyObj = {}
myMap.set(keyString, "value associated with 'a string'")
myMap.set(keyObj, 'value associated with keyObj')
myMap.set(keyFunc, 'value associated with keyFunc')
myMap.size
myMap.get(keyString)
myMap.get(keyObj)
myMap.get(keyFunc)
Example 4: map in javascript
['elem', 'another', 'name'].map((value, index, originalArray) => {
console.log(.....)
});