0

This is my response data:

var data = [{
            'id': '1',
            'name': 'kamal',
            'age': '21'
        }, {
            'id': '2',
            'name': 'ram',
            'age': '11'
        }, {
            'id': '3',
            'name': 'karuna',
            'age': '22'
        }, ];

I getting this data in to my response data. I need to remove field id inside of object. I want to splice the id field in each object .

expected result is:

var data = [{
            'name': 'kamal',
            'age': '21'
        }, {
            'name': 'ram',
            'age': '11'
        }, {
            'name': 'karuna',
            'age': '22'
        }, ];
  • Have you tried anything, options of the top of my head `map` or if mutated, `delete`.. – Keith May 25 '18 at 09:10
  • Just loop through and use the information from the linked question's answers to remove the property from each object. (Or create new objects without the `id` property if you're doing the immutable thing, but you'e said "remove" and "splice" suggesting you're happy to mutate [modify] the original objects.) – T.J. Crowder May 25 '18 at 09:11

1 Answers1

0

Loop through your array and delete every id property.

var data = [{
  'id': '1',
  'name': 'kamal',
  'age': '21'
}, {
  'id': '2',
  'name': 'ram',
  'age': '11'
}, {
  'id': '3',
  'name': 'karuna',
  'age': '22'
}, ];

for (var i = 0; i < data.length; i++) {
  delete data[i].id;
}

console.log(data);
CodeF0x
  • 2,624
  • 6
  • 17
  • 28