cyberfly
9/6/2019 - 3:58 AM

Javascript map into new object

let products = [
    {
      title: 'test',
      src: 'test.html'
    },
    {
      title: 'test',
      src: 'test2.html'
    }
  ];

let custom_products = products.map(function(product) {
    return {
      name: product.title,
      url: product.src
    };
})

// output

[
    {
      name: 'test',
      url: 'test.html'
    },
    {
      name: 'test',
      url: 'test2.html'
    }
  ]