javascript - How to shuffle arrays in array of objects? -
javascript - How to shuffle arrays in array of objects? -
i have array of objects similar this:
[ { name: 'apple', colors: ['red', 'green', 'yellow'] }, { name: 'orange', colors: ['orange'] } ]
i shuffle colors of each object. using next code:
_.each(fruits, function (elem) { elem.colors = _.shuffle(elem.colors); });
however, code not work chaining, turns colors
object, , requires anonymous function think eliminated. there way create code simpler?
that's how implement in chainable way lodash:
var r = _(a) .map(function(i) { homecoming _.assign(i, { colors: _.shuffle(i.colors) }); }) .value();
jsfiddle: http://jsfiddle.net/bo8xf2as/
javascript lodash
Comments
Post a Comment