Is an Object with a Property in my Array?

Tim Bernhard

JavaScript

This post is old. Codes, opinions and facts could be outdated.

Help to fix potential errors: GitHub

The following code can be used to test whether an object in an 'array' array has a 'property' property with the value 'value':

// test if a object located in 'arrray' has a 'property' which equals 'value'
var isInArray = function (array, property, value) {
        for (var i=0; i < array.length; i++) {
                if (array[i][property] === value) return true; 
            }
            return false;
};
Webmentions

No webmentions found for this page.