Answers for "jscript map"

4

javascript map

The map() method creates a new array with the results of calling a provided function on every element in the calling array.
Posted by: Guest on December-22-2019
0

map function in js

let kvArray = [{key: 1, value: 10},
               {key: 2, value: 20},
               {key: 3, value: 30}]

let reformattedArray = kvArray.map(obj => {
   let rObj = {}
   rObj[obj.key] = obj.value
   return rObj
})
// reformattedArray is now [{1: 10}, {2: 20}, {3: 30}],

// kvArray is still:
// [{key: 1, value: 10},
//  {key: 2, value: 20},
//  {key: 3, value: 30}]
Posted by: Guest on June-14-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language