Scenario
After making a REST request, I am presented with a set of objects in Angular. Each object is automatically assigned a $$hashKey
by the framework. However, when I attempt to search for an object within this array without considering the $$hashKey
, the search returns -1. This behavior is expected, but unfortunately, I do not have visibility into the actual value of the $$hashKey
.
Inquiry
Is there a more efficient approach to locating an object within an array of objects obtained from a REST request in AngularJS without removing the $$hashKey
property?
Snippet
function findObjectIndexInArray(arr, obj) {
var regex = /,?"\$\$hashKey":".*?",?/;
var search = JSON.stringify(obj).replace(regex, '');
console.log(search);
for ( var i = 0, k = arr.length; i < k; i++ ){
if (JSON.stringify(arr[i]).replace(regex, '') == search) {
return i;
}
};
return -1;
};