Given:
var objects_found = [];
var entry = {any_number:77, any_text:"P1"}; // note: both primitive types
objects_found.push(entry);
.. why -with console logging showing such key/value pairs to be correctly stored- the following:
if (entry in objects_found) { ... }; // never fires
if (!(entry in objects_found)) { ... }; // always fires
Other than looping through the array as discussed here), is there a simple fix?
inoperator finds indexes and properties, e.g.'any_number' in entryreturnstrueas the objectentryhas the propertyany_number. It's not used for finding objects in arrays. AFAIK there is no way to magically pull a value out of an array without iterating over the array - evenindexOflisted below will iterate over your array to find the index.any_numberandany_textare strings whether you quote them or not.