gpt4 book ai didi

javascript - 从javascript中的类数组获取对象

转载 作者:行者123 更新时间:2023-11-30 09:18:01 26 4
gpt4 key购买 nike

<分区>

我有一个 javascript 类,比如,

class Snake{
constructor(id, trail){
this.velocityX = 0;
this.velocityY = -1;
this.trail = trail;
this.id = id;
}
moveRight(){
console.log('move');
}
}

和一个存储 Snake 对象的数组。

this.snakeList = new Array();
this.snakeList.push(new Snake(10, newSnakeTrail));
this.snakeList.push(new Snake(20, newSnakeTrail));
this.snakeList.push(new Snake(30, newSnakeTrail));
this.snakeList.push(new Snake(22, newSnakeTrail));
this.snakeList.push(new Snake(40, newSnakeTrail));

例如,我想从数组中删除id为20的元素。

我该怎么做?

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