I have an array with multiple objects.How can i delete an element in a object.
For example i have attached a image in that i need to delete organization element.
Please help me out to fix.
Asked
Active
Viewed 95 times
-10

Rajesh Bunny
- 329
- 1
- 2
- 7
-
What have you tried so far? We are not going to just hand over the solution for you. That is not how StackOverflow works. – OptimusCrime Feb 20 '19 at 08:28
-
Possible duplicate of [How do I remove a property from a JavaScript object?](https://stackoverflow.com/questions/208105/how-do-i-remove-a-property-from-a-javascript-object) – Carol-Theodor Pelu Feb 20 '19 at 08:29
-
What do you mean by deleting? You dont want only that field from your json – dileepkumar jami Feb 20 '19 at 08:30
3 Answers
1
var a = {name: 'pardeep', 'sirname': 'jain'}
delete a['name']
console.log(a);
Just use delete
keyword for the key like this -
delete objectName['keyName']

Pardeep Jain
- 84,110
- 37
- 165
- 215
0
Use the delete operator
const deleteAttribute = (array, attribute) => array.map(x => {
// Delete the attribute here
delete x[attribute];
return x;
});
const arr = [{
attr: 'hello',
color: 'red',
organization: 'Good'
}, {
attr: 'world',
color: 'blue',
organization: 'bad'
}];
console.log(deleteAttribute(arr, 'organization'));
0
You can use map
and delete
like below
var arr = [{
name: 'hi',
test: 'x',
organization: 'X'
}, {
name: 'guys',
test: 'y',
organization: 'Y'
}];
console.log(arr.map(x => { delete x.organization; return x}));

dileepkumar jami
- 2,185
- 12
- 15
-
-
@molamk Sorry. My intention was only to help him. I was mocking some array but meanwhile got yours. So, I took the array from you. I ll change it – dileepkumar jami Feb 20 '19 at 08:41
-