Need to remove key(s) from a json array under javascript (jquery).
Looks like my code is wong although it was working in my Chrome console.
Your help is the most welcome.
Jacques
function test() {
var json = {
"ID": "2196",
"VERSION": "1-2022",
"FILE": "2196.docx"
};
json = JSON.stringify(json)
console.log("json " + json);
delete json['FILE'];
console.log("json " + json);
return;
}
test();
2
Answers
You should not
stringify
the object before removing the key.JSON.stringify has an often overlooked parameter called the replacer. It can accept an array of key names to include in the json output:
Snippet
Run the snippet to see the output with and without using the replacer.