Answers for "array to dictionary javascript"

0

array to dictionary javascript

let data = [
  {id: 1, country: 'Germany', population: 83623528},
  {id: 2, country: 'Austria', population: 8975552},
  {id: 3, country: 'Switzerland', population: 8616571}
];

let dictionary = Object.assign({}, ...data.map((x) => ({[x.id]: x.country})));
// {1: "Germany", 2: "Austria", 3: "Switzerland"}
Posted by: Guest on June-14-2021

Code answers related to "array to dictionary javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language