• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

ES2015: Transform Array to Object

 
Saloon Keeper
Posts: 2940
373
Android Eclipse IDE Angular Framework TypeScript MySQL Database Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to transform an array like this: [ 'Martin', 'Rose', 'Quan', 'Rodrigo' ]
to an object like this: { id_0: "Martin", id_1: "Rose", id_2: "Quan", id_3: "Rodrigo" }

This code works, but I'm thinking there might be a better way.  Any ideas?
 
Ron McLeod
Saloon Keeper
Posts: 2940
373
Android Eclipse IDE Angular Framework TypeScript MySQL Database Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A better solution:
I still don't like that I need to use Object.assign though.
 
keep an eye out for scorpions and black widows. But the tiny ads are safe.
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!