map on javascript object code example

Example 1: map object es6

var myObject = { 'a': 1, 'b': 2, 'c': 3 };

Object.keys(myObject).map(function(key, index) {
  myObject[key] *= 2;
});

console.log(myObject);
// => { 'a': 2, 'b': 4, 'c': 6 }

Example 2: javascript map to object

Object.fromEntries(Map)

Example 3: map in javascript

let myMap = new Map()

let keyString = 'a string'
let keyObj    = {}
// setting the values
myMap.set(keyString, "value associated with 'a string'")
myMap.set(keyObj, 'value associated with keyObj')
myMap.set(keyFunc, 'value associated with keyFunc')
myMap.size              // 3
// getting the values
myMap.get(keyString)    // "value associated with 'a string'"
myMap.get(keyObj)       // "value associated with keyObj"
myMap.get(keyFunc)      // "value associated with keyFunc"

Example 4: map in javascript

['elem', 'another', 'name'].map((value, index, originalArray) => { 
  console.log(.....)
});

Example 5: javascript map

array.map( item => item.id )

array2.map( item => item.toString() )

array2.map( item => item * 3 )

// this will apply a transformation to all elements of an array
// "" item => something "" is the transformation (function)