I have read SO and others but more complex For referrence:
let newpage = {
page_no_3: {
data1: [{index: 1, text: "test1"}],
data2: [{index: 1, text: "test2"}],
}
}
What I want to happen when I add new object:
let newpage = {
page_no_3: {
data1: [{index: 1, text: "test2"}, {index: 2, text: "test3"}, ...]
data2: [{index: 1, text: "test2"}, {index: 2, text: "test4"}, ...]
}
}
NOTE: Sorry it should not be an array but an object.
NOTE2: Sorry again. it should be Array with objects as elements.
PS: When I try to get the data of data1 before inserting, it is giving me an undefined error. I tried it like this:
let page_no = 'page_no_3'
if (nextpage.length == 0) {
///
} else { // Both undefined
console.log(nextpage[page_no].data1)
console.log(nextpage["page_no_3"].data1)
}
But if I only console.log(nextpage[page_no])
I can see the {index: 1, text: "test2"}.