Last active
December 21, 2017 17:41
-
-
Save marioblas/10240115 to your computer and use it in GitHub Desktop.
Underscore.js - Add attributes to each object of an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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