7

Consider var person=JSON.parse('{"name":"Alice","id",1234}').

How do I remove a key from the variable person? For example, how do I remove "name" completely, so that person becomes {"id":1234}?

2

1 Answer 1

20

Try delete person["name"].

Notice that delete will only set it as undefined, which will then not be reflected correctly in the length of the array.

If you know the key you should use splice i.e.

myArray.splice(key, 1);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.