Skip to content

Instantly share code, notes, and snippets.

@marioblas
marioblas / add-attributes.js
Last active December 21, 2017 17:41
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'});
});