ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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

user-image
تم إضافة السؤال من قبل Yasmeen Husam , Web Developer , Al Fahid Systems
تاريخ النشر: 2019/01/28
youssouf touhami
من قبل 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
من قبل 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
من قبل Loullah AHMEDOU , Software Engineer , GTI International

using "delete" keyword

Example:

delete myObject.aProperty;

Muhammad Farhan
من قبل Muhammad Farhan , Web Desinger , Fiverr

You can Use Delete Statement to remove this.

eg. Delete obj.property

Muhammad Sajjad
من قبل Muhammad Sajjad , Full Stack Web Developer , Phlox Solutions

Simply use the Delete key word

Example: 

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

delete test.blue;

 

المزيد من الأسئلة المماثلة