Concatenating array objects with lodash
I am trying to merge all objects together using lodash and I have tried _.assign and _.merge to still show objects separately.
var arr = [
{"asf" : 33, "ff1" : 12},{"xx" : 90, "ff2" : 13},{"xw" : 66, "ff3" : 176}
]
console.log( _.assign({}, arr)); //should show {"asf" : 33, "ff1" : 12,"xx" : 90, "ff2" : 13, "xw" : 66, "ff3" : 176}
+3
source to share
3 answers
Here's how you can do it:
_.assign.apply(_, arr);
Demo: http://jsfiddle.net/ymppagdq/2/
or _.reduce(arr, _.extend)
will work as well.
+11
source to share