I have an object element and an array element which contains some items of the object.
I would like to delete the items in the object referenced by the array.
var array = ["test1","test2"];
var object =
...
"test1": {
"na": [
"t",
"t-t",
"t-98",
"t"
]
},
"test2": {
"python": [
"jjj"
]
}
...
When I use
delete object.test1
It works.
However in my case, I want :
for(var i = 0 ; i < array.length ; i++){
delete object.array[i];
}
But I got :
object.array is undefined
Any ideas ?
objectobject does not have a property namedarray, it is an independent array object, and does not have anything to do with yourobjectobject. That is why you get the error.object.array[i];should beobject[array[i]].