Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What's the best way to remove properties and functions from an object in Javascript?

user-image
Question added by Yasmeen Husam , Web Developer , Al Fahid Systems
Date Posted: 2019/01/28
youssouf touhami
by youssouf touhami , Chief Service Management Information- IT Department , NAFTAL

Theres is tow Option:

1- Delete is the true way to remove object's properties without any leftovers, but it works slow

2- setting object[key] = undefined.

Example:

Delete: 

Var obj ={ feild:1 }; 

delete obj.feild;

Undefined: 

Var obj ={ feild:1 }; 

obj.feild=undefined;

 

Adel Abou Elezz
by Adel Abou Elezz , Full Stack Developer , Rama Group

this may help you 

var myObject = { "ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*" }; delete myObject.regex;

Loullah AHMEDOU
by Loullah AHMEDOU , Software Engineer , GTI International

using "delete" keyword

Example:

delete myObject.aProperty;

Muhammad Farhan
by Muhammad Farhan , Web Desinger , Fiverr

You can Use Delete Statement to remove this.

eg. Delete obj.property

Muhammad Sajjad
by Muhammad Sajjad , Full Stack Web Developer , Phlox Solutions

Simply use the Delete key word

Example: 

var test ={'red':'#FF','blue':'#FF'};

delete test.blue;

 

More Questions Like This