Glen O
0
Q:

initialize a map js

array.map((item) => {
  return item * 2
} // an example that will map through a a list of items and return a new array with the item multiplied by 2
21
let map = new Map()
map['bla'] = 'blaa'
map['bla2'] = 'blaaa2'

console.log(map)  // Map { bla: 'blaa', bla2: 'blaaa2' }
2
['elem', 'another', 'name'].map((value, index, originalArray) => { 
  console.log(.....)
});
2
const objectMap = (obj, fn) =>
  Object.fromEntries(
    Object.entries(obj).map(
      ([k, v], i) => [k, fn(v, k, i)]
    )
  )
  
const myObject = { a: 1, b: 2, c: 3 }

console.log(objectMap(myObject, v => 2 * v)) 
-2

New to Communities?

Join the community