I have an array of object of which I want to check if the any of the object has a title 'food' before checking for others but at the moment, it checks sequentially. Bellow is my code
let db = {
users: [{
id: 1,
title: "food"
},
{
id: 2,
title: "stone"
},
{
id: 3,
title: "food"
}
]
}
for (let index in db.users) {
if (db.users[index].title === "food") {
console.log("Its food");
continue;
}
console.log("Its not food");
}
With the code above, I get the following result
Its food
Its not food
Its food
How do i do it such that i it checks for all food before any other title so i get the result
Its food
Its food
Its not food
Thanks.
foodorno food. So if you want it in order, better use loops separately.