I am currently working with an array of objects and I need to check if any of the objects have a title of 'food' before checking for any other titles. However, my current code checks sequentially. Below you will find the code snippet:
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");
}
The current output of the above code is:
Its food
Its not food
Its food
How can I modify the code to prioritize checking for 'food' titles so that the desired output is:
Its food
Its food
Its not food
Thank you.