Skip to content

Instantly share code, notes, and snippets.

@tbrzica
Created September 21, 2015 18:05
Show Gist options
  • Save tbrzica/49b1aa2e2d73b25910fb to your computer and use it in GitHub Desktop.
Save tbrzica/49b1aa2e2d73b25910fb to your computer and use it in GitHub Desktop.
Combine two arrays using undercoreJS
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);
});
@tbrzica
Copy link
Author

tbrzica commented Sep 21, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment