Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove item from a JavaScript object [duplicate]

How can I remove an item from a JavaScript object?

Like this:

var test = {'red':'#FF0000', 'blue':'#0000FF'}; test.remove('blue'); 
like image 308
ezebemmel Avatar asked Jun 09 '11 15:06

ezebemmel


People also ask

How do you remove duplicates in an object?

To remove the duplicates from an array of objects:Create an empty array that will store the unique object IDs. Use the Array. filter() method to filter the array of objects. Only include objects with unique IDs in the new array.

How can you eliminate duplicate values from a JavaScript array?

Answer: Use the indexOf() Method You can use the indexOf() method in conjugation with the push() remove the duplicate values from an array or get all unique values from an array in JavaScript.


1 Answers

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

this deletes test.blue

like image 178
matchew Avatar answered Sep 28 '22 06:09

matchew