I have an array like this
"chapters":[
{
"_id": "5422c6ba0f6303ba22720e14",
"chapter_name": "Morbi imperdiet libero sed.",
"sub_title": "Nam id elit tincidunt amet.",
"mystatus": "noidea"
},
{
"_id": "5422bd0d5cb79ae6205b2f6a",
"chapter_name": "Donec id accumsan volutpat.",
"sub_title": "Cras volutpat velit nullam.",
"mystatus": "noidea"
},
{
"_id": "5423ea5f17c83ad41da1765e",
"chapter_name": "Donec id accumsan volutpat.",
"sub_title": "Cras volutpat velit nullam.",
"mystatus": "noidea"
}
],
And I have another one
"currentstat": [
"5423ea5f17c83ad41da1765e",
"5422c6ba0f6303ba22720e14",
"5422bd0d5cb79ae6205b2f6a"
],
I want to check any of currentstat array value contains in chapters._id.
And I tried like this.
for (var i = 0; i < chapters.length; i++) {
var attenId = currentstat.toString();
if (attenId.indexOf(chapters[i]._id) != -1) {
}
}
I could not get the result without
var attenId = currentstat.toString();
one more thing I need on this.
I need to assign these status array value to corresponding chapters array as per currentstat array value.
status: [ 'passed', 'passed', 'attending']
the whole code is like this
for (var i = 0; i < chapters.length; i++) {
var attenId = currentstat.toString();
if (attenId.indexOf(chapters[i]._id) != -1) {
allChapters[i].mystatus = (status[i]) ? status[i] : 0;
}
}
but the value does not assign to corresponding _id Please help!