How to remove functions from object javascript

Issue

In my app, I’m using angular.js.

I need to send (through PUT request) an object with 3 properties, like this:

var item = {
  a: 1,
  b: 2,
  c: 3
}

But when I do console.log(item), it shows a lot of information I don’t need, such as $delete, $get, and so on. Like this:

 {  
   ...
   $delete: function (params, success, error),
   $get: function (params, success, error),
   ...
   a: 1,
   b: 2,
   c: 3
}

I think it’s because is a javascript promise or something.
Is there any way to get only a, b and c? Maybe with lodash?


My Solution:

I used lodash like this:

 var valuesToPick = ['title', 'languageCode', 'jobTitle', 'location','economySegment', 'companyDescription' ...];

 var item = _.pick( vm.form, valuesToPick );

Solution

I used lodash _.pick like this:

 var valuesToPick = ['title', 'languageCode', 'jobTitle', 'location','economySegment', 'companyDescription' ...];

 var item = _.pick( vm.form, valuesToPick );

Items is now free of functions, just your info.

Answered By – Baumannzone

Answer Checked By – Timothy Miller (AngularFixing Admin)

Leave a Reply

Your email address will not be published.