i have array contains objects, this:
[{ "first" : 1 }, { "second" : 2 }, { "third" : 3 }]
i want turn 2 arrays, indexes matching based on these values, such as:
["first","second","third"] [1,2,3]
i can iterate through , object keys , values, feel there's gotta slick way in lodash this, don't know of. suggestions? thank you!
for non-lodash solution:
var arr = [{"first" : 1},{"second" : 2},{"third" : 3}]; var keys = arr.map(function(el){return object.keys(el)[0];}); var vals = arr.map(function(el){return el[object.keys(el)[0]];});
for opposite problem (multiple arrays 1 array of objects), see merge 2 arrays array of objects property values