Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * @type {Array< {id: number, name:string, email: string}}
- */
- // my code with ES6
- let users = [
- {
- id:1,
- name: "Robbi",
- email: "rrcarver@gmail.com"
- }
- ];
- let [
- {
- id
- }
- ] = users;
- users.reduce((map, user) =>{
- map[id] = user;
- return map;
- }, {}); // output: { '1': { id: 1, name: 'Robbi', email: 'rrcarver@gmail.com' } }
- // ES5
- // let users = [
- // {
- // id:1,
- // name: "Robbi",
- // email: "rrcarver@gmail.com"
- // }
- // ];
- // users.reduce(function(map, user){
- // map[user.id] = user;
- // return map;
- // }, {}); // output: { '1': { id: 1, name: 'Robbi', email: 'rrcarver@gmail.com' } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement