Skip to content
Advertisement

Check whether an Object contains a specific value in any of its array

How to find if an object has a value?

My Object looks like below: I have to loop through the object array and check if an array has “SPOUSE” in its value. if exist set a flag spouseExits = true and store the number (in this case (4 because [SPOUSE<NUMBER>] NUMBER is 4) in a variable 'spouseIndex'

This function needs to render in IE9 as well.

JavaScript

Code:

JavaScript

SpouseIndex is undefined. What am I doing wrong?

Advertisement

Answer

Here’s a simple approach, supports in all browsers including IE:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement