我有一个项目数组嵌套在另一个项目数组中。我试图删除嵌套数组中的特定项目。我有下面的代码。
removeFromOldFeatureGroup() {
for( let i= this.featureGroups.length-1; i>=0; i--) {
if( this.featureGroups[i].featureGroupId == this.oldFeatureGroupId)
for( let z= this.featureGroups[i].features.length-1; z>=0; z--) {
if( this.featureGroups[i].features[z].featureId == this.featureId)
this.transferedFeature = this.featureGroups[i].features[z];
this.featureGroups[i].features[z].splice(z, 1);
return;
}
}
}
当我到达 splice 时,会抛出一个错误,指出 splice 不是函数。如何解决这个问题?另外, this.transferedFeature 是我需要删除的正确功能。
最佳答案
应该是:
this.featureGroups[i].features.splice(z, 1);
因为 this.featureGroups[i].features
是数组中的数组(根据您的描述)。
关于javascript - Typescript 从嵌套在数组中的数组中拼接项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41857190/