Created
September 21, 2015 18:05
-
-
Save tbrzica/49b1aa2e2d73b25910fb to your computer and use it in GitHub Desktop.
Combine two arrays using undercoreJS
This file contains hidden or 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
var app = angular.module('plunker', []); | |
app.controller('MainCtrl', function($scope) { | |
$scope.name = 'World'; | |
var a = [{id:456, name:'sojuz'}, | |
{id:751, name:'sputnik'}, | |
{id:56, name:'arianne'}]; | |
var b = [{id:751, weight:5800}, | |
{id:456, weight:2659}, | |
{id:56, weight:6700}]; | |
var c = _.map(a, function(element) { | |
var weight = _.findWhere(b, { id: element.id }); | |
return _.extend(element, weight); | |
}); | |
console.log(c); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kombiniranje dvije matrice objekata na način da se objekti matrice a prošire sa propertijem weight matrice b gdje je property id isti kao u matrici a