Well, from what I understand you want to check if a property of all items in the array are the same and return the result, see if that fits you:
function compareArrayValues(arr, field, callback) {
var response = 'Igual';
for(x in arr) {
if(arr[x][field] != arr[0][field]) {
response = 'Diferente';
break;
}
}
callback(response);
}
var arr = [
{ nome: 'abc' },
{ nome: 'abc' },
{ nome: 'abc' }
];
compareArrayValues(arr, 'nome', function(response) {
console.log(response);
});
What I do is define a function that receives the array, the key to be compared, and a return function (callback)
, then I make a loop
to compare the elements of the array and call the function of callback
with the answer.