I chose this JSON structure to store some data because I thought it would be easy to reference each object by it's key but I can't seem to correctly remove an element by key.
JSON Object:
[{
"a74bb26c-c23f-e711-80da-0050568f4ab2": {
"VersionCode": "0ODD6109",
"VersionQualifier": "",
"ProductID": "WRAP",
}
}, {
"a74fff6c-c23f-e711-80da-0050568f4ab2": {
"VersionCode": "0ODD6109",
"VersionQualifier": "",
"ProductID": "WRAP",
}
}]
When
key="a74fff6c-c23f-e711-80da-0050568f4ab2"
and
dataObj = {
"VersionCode": "0ODD6109",
"VersionQualifier": "",
"ProductID": "WRAP",
}
I can easily add items using:
dataObject = an object with properties
newItem = {}
newItem[key] = dataObj
myJsonObj.push(newItem).
How can I remove an item when I have the key as a variable?
This hasn't worked:
delete myJsonObj[key]
This also hasn't worked:
var index = myJsonObj.indexOf(node, 0);
if (index > -1) {
myJsonObj.splice(index, 1);
}