I have an array of 4 objects and each object contains property array of 8 object.
I am trying to remove an object from properties Array[8]
var responseArray = new Array();
responseArray = response.data;
responseArray.forEach(function (resProp) {
if (resProp.alias == "General Details") {
resProp.properties.forEach(function (checkProp) {
if (checkProp.alias == "name") {
responseArray.pop(checkProp);
}
});
}
});
I am able to pop it however the responseArray having only 3 object Array instead of 4.i think, this code is removing the whole 4th object.
responseArray.pop(checkProp);
any suggestions on removing only matched object?
The pop() method removes the last element from an array and returns that element.
responseArray.properties
array instead of responseArray
Replace responseArray.pop(checkProp);
with resProp.properties.splice( resProp.properties.indexOf(checkProp) , 1 );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.