I'm trying to iterate over this object containing a array of quests-objects. How would i be able to iterate over each key value pairs to for example return all quests which have the status "completed".
{
"quests": [
{
"title": "A Rum Deal",
"status": "COMPLETED",
"difficulty": 2,
"members": true,
"questPoints": 2,
"userEligible": true
}
],
"loggedIn": false
}
For iterating you could use Array#forEach
object.quests.forEach(function (a) {
if (a.status === "COMPLETED") {
// do something with the data
}
});
For returning a selection with completed task, you could use Array#filter
var completed = object.quests.filter(function (a) {
return a.status === "COMPLETED";
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With