Map Collection Display Js Code Example

Snippet 1

  The map() method creates a new array with the results of calling a provided function on every element in the calling array. 

Snippet 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))  

Copyright © Code Fetcher 2020

 

 

Published

Leave a comment

Your email address will not be published. Required fields are marked *