Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
84
rated 0 times [  88] [ 4]  / answers: 1 / hits: 13360  / 10 Years ago, sat, october 11, 2014, 12:00:00

I'm trying to merge all objects together using lodash and I tried _.assign and _.merge still it shows the 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}


http://jsfiddle.net/ymppagdq/


More From » lodash

 Answers
2

This is how you can do it:



_.assign.apply(_, arr);


Demo: http://jsfiddle.net/ymppagdq/2/



or _.reduce(arr, _.extend) would also work.


[#41958] Thursday, October 9, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leighrheac

Total Points: 313
Total Questions: 92
Total Answers: 94

Location: Papua New Guinea
Member since Thu, May 7, 2020
4 Years ago
;