gpt4 book ai didi

javascript - Typescript 从嵌套在数组中的数组中拼接项目

转载 作者:太空宇宙 更新时间:2023-11-04 16:06:09 25 4
gpt4 key购买 nike

我有一个项目数组嵌套在另一个项目数组中。我试图删除嵌套数组中的特定项目。我有下面的代码。

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com