How to delete nested properties in javascript.
I have example code below which has nested objects and want delete particular nested object on condition I have added condition below. How to delete the entire object based the condition ?
var tenants = [{
'first': {
'name': 'first',
'expired': 1
},
'second': []
},{
'first': {
'name': 'second',
'expired': 2
},
'second': [
'name': 'third'
]
},{
'first': {
'name': 'third',
'expired': 3
},
'second': [
'name': 'third'
]
},
]
tenants.forEach((item) => {
if(item.second.length == 0) {
console.log('record found..');
delete item
}
else {
Data = item;
}
});
How can we achieve this get the Expected result as below:
var tenants = [{
'first': {
'name': 'second',
'expired': 2
},
'second': [
'name': 'third'
]
},{
'first': {
'name': 'third',
'expired': 3
},
'second': [
'name': 'third'
]
},
]
secondarray