I have an array with multiple JSON objects. I don't need all key/values in my file so I want to delete e.g. all "Completed" keys and their values across all of those JSON objects.
I know I could delete specific key/value pairs with the delete operator though leaving undefined holes in the array. I don't want that because I think it will cause problems later on when I work with the array.
I also tried it with splice:
data.splice(data[i].Completed, data.length);
Did I make a mistake with splice?
Acutally I want to create a new file without certain key/values. In my approaches I just manipulated the existing file without creating a new one … how could I do that?
var data = [
{
"ID": 1,
"Titel": "ui sketch",
"Completed": "yes",
"Prio": 3,
"Importance": 2
},
{
"ID": 2,
"Titel": "coding",
"Completed": "yes",
"Prio": 4,
"Importance": 4
},
{
"ID": 5,
"Titel": "meeting",
"Completed": "no",
"Prio": 3,
"Importance": 2
},
]
splicewould be for removing array data, not key/value in your objects. If you only want to remove the"Completed": "yes"key/value, and not the entire object containing that value,splicewouldn't do the trick.