js str map code example
Example 1: 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 2: array mdn map
let new_array = arr.map(function callback( currentValue[, index[, array]]) {
}[, thisArg])
Example 3: array map
let numbers = [1, 4, 9]
let roots = numbers.map(function(num) {
return Math.sqrt(num)
})