I want to convert a list of objects into another in JS like
A = [{"id":"a", "name":"b", "email":"c"}, {"id":"c", "name":"d", "email":"c"}] to
B = [{"id":"a", "value":"b"}, {"id":"c", "value":"d"}]
How to do this?
I want to convert a list of objects into another in JS like
A = [{"id":"a", "name":"b", "email":"c"}, {"id":"c", "name":"d", "email":"c"}] to
B = [{"id":"a", "value":"b"}, {"id":"c", "value":"d"}]
How to do this?
2
Answers
This is just a simple re-mapping of
id -> id
andname -> value
.Here is a more-verbose version:
You can use JavaScript’s array method map to accomplish this.
Map iterates over each element of the array and returns an array.