Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove key value pair from an object in javascript using underscoreJs

I have an array
var data = {email: 'email@gmail.com', phone: '3434344332', firstName: 'john', lastName: 'Doe'};

How do i remove one or more elements from the array?

I Tried _.without( data, data.email ) , this removes the email field but also changes the Object to array without keys.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

result ["3434344332", "john", "Doe"]

What I want to achieve {phone: '3434344332', firstName: 'john', lastName: 'Doe'}

>Solution :

without only works with arrays. If you pass an object, it’ll get turned into an array in a similar manner to Object.values. You should be using omit instead:

_.omit(data, "email")

reference

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading