Compare the values of two objects
I researched this in an attempt to compare the values of the two different objects to to find a match. This is not the exact solution I implemented for my client but it lead me to it.
by Matthew Day
HTML
<div ng-app="myApp">
<div ng-controller="MyCtrl as vm">
<div ng-repeat="first in vm.objA">{{first}}</div>
<hr />
<div ng-repeat="second in vm.objB">{{second}}</div>
<hr />
<div ng-repeat="data in vm.combineArr">
{{data.data}} {{data.value}}
</div>
<hr />
<div ng-repeat="data in vm.combineObj">
{{data.data}} {{data.value}}
</div>
</div>
</div>
JavaScript
angular.module('myApp', []);
angular.module('myApp')
.controller('MyCtrl', function() {
var vm = this;
vm.objA = {
"question1": {
"age": "21"
},
"question2": {
"city": "Houston"
},
"question3": {
"work": "Artist"
}
};
vm.objB = {
"question1": {
"age": "43"
},
"question2": {
"city": "Jacksonville"
},
"question3": {
"work": "Truck Driver"
}
};
var arrA = ['a', 'b', 'c'];
var arrB = ['1', '2', '3'];
vm.combineArr = arrA.map(function(value, index) {
return {
data: value,
value: arrB[index]
}
});
vm.combineObj = Object.keys(vm.objA).map(function(value, index) {
console.log(value, index);
return {
data: index,
value: vm.objB[value]
}
});
});
// SOURCES
// stackoverflow.com/questions/27901793/multiple-ng-repeat-on-single-element
// stackoverflow.com/questions/14810506/map-function-for-objects-instead-of-arrays