I'm trying to find an exact match in an array. I have my array array
with a single object, and an exact match stored in example
. When I iterate over the array
array, it goes right past it. I discovered this when working with a much larger array, but broke it down to a single 1/1 relationship for a sort of 'proof of concept'. I feel like the answer is simple and staring right at me, but I don't see it. Save me.
'use strict';
var array = [ { foo: 'hello', bar: 'foo' } ];
var example = { foo: 'hello', bar: 'foo' };
for (var i = 0; i < array.length; i++) {
if ( array[i] === example ) {
console.log(array[i]);
}
}