I have a JSON data structure that looks like this:
{
"prerequisites": [
"Modeling",
"Dynamics",
"Statics"
],
"targets": [
"Aerospace students",
"Mechanical students",
"Civil engineering students",
"Marine engineering students"
],
"sections": [
{
"title": "How to install Abaqus.",
"achievements": [
"How to turn on the computer",
"How to install Abaqus",
"How to open Abaqus."
],
"lectures": [
{
"title": "Tutorial for starting Windows",
"media": "PDF file address or video link"
},
{
"title": "Tutorial for starting Windows",
"media": "PDF file address or video link"
}
]
}
]
}
In TypeScript (Angular 5), I want to add a pair of key, value {"unlock_users": 0}
to all elements in the lectures array within each section. How can I achieve this?
I attempted to loop through the sections and lectures using the following code snippet in an attempt to find the index and push the key, value pair by index, but it returned undefined. Here is the code:
for (const {section, index_s} of this.data['sections'].map((item, index) => ({ item, index }))) {
console.log(section);
console.log(index_s);
for (const {lecture, index_l} of section['lectures'].map((item, index) => ({ item, index }))) {
console.log(lecture);
this.data['sections'][index_s]['lectures'][index_l]['unlock_users'] = 0;
}
}