Austin Davis
Austin Davis

Reputation: 3756

How to remove a key and a value out of an javascript object

If I had a javascript object with the values of

{"__v":0,"_id":"528277c808cab8ac2b000001","password":"password",
"userId":5,"userName":"Austinsss","$$hashKey":"00F"}

How could I remove "$$hashKey":"00F" out of the object entirely.

Upvotes: 0

Views: 80

Answers (3)

Sterling Archer
Sterling Archer

Reputation: 22435

delete it!

delete objname["$$hashKey"];

Upvotes: 3

tymeJV
tymeJV

Reputation: 104795

How about

delete obj.$$hashKey

Upvotes: 3

Bojangles
Bojangles

Reputation: 101543

Use delete(MDN):

var foo = {"__v":0,"_id":"528277c808cab8ac2b000001","password":"password",
"userId":5,"userName":"Austinsss","$$hashKey":"00F"};

delete foo.$$hashKey;

You could also use bracket notation if you have keys with odd characters in them:

delete foo['$$HashKey'];

Upvotes: 3

Related Questions