I have an array
FruitsList = [
{name: 'apple', color: 'red'},
{name: 'grapes', color: 'violet'},
{name:'avocado', color: 'green'}
]
Next I want to fill another array of objects
Food = [{fruitName: '', fruitColor:''}]
from all the values of the previous array. I tried mapping but failed. Can anyone help what approach in Javascript or Typescript I can use?
.map
function, you want to feed it a function that returns the object you want to be in your new array.arr.map(function(oldElement){ return newElement })
. And that leaves you with an array ofnewElements
– TKoL 1 hour ago