SHARE
TWEET

Untitled

a guest Oct 16th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // merging an array of objects into one
  2. const cities = [
  3.     { name: 'Paris', visited: 'no' },
  4.     { name: 'Lyon', visited: 'no' },
  5.     { name: 'Marseille', visited: 'yes' },
  6.     { name: 'Rome', visited: 'yes' },
  7.     { name: 'Milan', visited: 'no' },
  8.     { name: 'Palermo', visited: 'yes' },
  9.     { name: 'Genoa', visited: 'yes' },
  10.     { name: 'Berlin', visited: 'no' },
  11.     { name: 'Hamburg', visited: 'yes' },
  12.     { name: 'New York', visited: 'yes' }
  13. ];
  14.  
  15. const result = cities.reduce((accumulator, item) => {
  16.   return {
  17.     ...accumulator,
  18.     [item.name]: item.visited
  19.   }
  20. }, {});
  21.  
  22. console.log(result);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top