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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -