How to remove item from a JavaScript object

JavascriptObject

Javascript Problem Overview


How can I remove an item from a JavaScript object?

Like this:

var test = {'red':'#FF0000', 'blue':'#0000FF'};
test.remove('blue');

Javascript Solutions


Solution 1 - Javascript

var test = {'red':'#FF0000', 'blue':'#0000FF'};
delete test.blue; // or use => delete test['blue'];
console.log(test);

this deletes test.blue

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionezebemmelView Question on Stackoverflow
Solution 1 - JavascriptmatchewView Answer on Stackoverflow