Skip to content

Instantly share code, notes, and snippets.

@marioblas
Last active December 21, 2017 17:41
Show Gist options
  • Save marioblas/10240115 to your computer and use it in GitHub Desktop.
Save marioblas/10240115 to your computer and use it in GitHub Desktop.
Underscore.js - Add attributes to each object of an array
/**
* Add attributes to each object of an array.
*
* @param {array} foo - Array of objects where we will add the attibutes
* @param {function} iterator
*/
_.each(foo, function(element, index) {
_.extend(element, {field1: index}, {field2: 'bar', field3: 'baz'});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment