delete unwanted properties from the javascript object

use either delete operator to delete specific properties

delete data.JunkOne;

or use object.assign to select specific properties

var a = Object.assign({}, { counties: data.counties});

EDIT:

Doing it lodash way would be

var a = _.omit(data, ['JunkOne']);

or

var a = _.pick(data, ['counties']);

You can use lodash.pick() to create an object with only the requested keys. For example:

var city = {
  state: 'New York',
  country: 'usa',
  counties : [['washington','DC'],'Long Island',['New','Jersey']], 
  city : 'Manhattan',
  zip: '43543545',
  JunkOne : ['3453454','45345','45345'],
  JunkTwo: '5454545',
  JunkThree: {adc:'4545',vdfd:'45345'}
}
var lodash = require('lodash');
city = lodash.pick(city, ['state', 'country', 'counties','city','zip']);

City now should have all the useful data, and none of the junk.


You can use _.pick to create a new object with only a specific set of properties from your original object:

var objectWithNoJunk = _.pick(myObject, ['state', 'country', 'counties', 'city', 'zip']);