0

I have an object

var checkerObject = {
    'Id': '',
    'Tracked':''
}

var checkerObjects = [];

and based on certain actions I do on a page I set Tracked to 1 and then add the object to a collection of these objects.

checkerObjects.push(checkerObject);

The amount of objects may vary. Is there a quick way to check that all the Tracked values in the array are set to 1?

Something like

if(checkerObjects.Where(t=>t.Tracked==0).Count()==0)
{
     //all the tracked values are 1
}
0

1 Answer 1

3

Use every:

var everyoneIsTracked = checkerObjects.every(function (obj) { 
    return obj.Tracked == 1;
});

if (everyoneIsTracked) {
    // stuff
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.