相关疑难解决方法(0)

如何从JavaScript中删除数组中的特定元素?

我有一个Numbers数组,我正在使用该.push()方法向其中添加元素.

有没有一种简单的方法从数组中删除特定元素?相当于像array.remove(number);.

我必须使用核心的JavaScript - 框架是不允许的.

javascript arrays

7655
推荐指数
112
解决办法
613万
查看次数

在javascript中从类数组中获取对象

我有一个类似的javascript类,

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

和一个存储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));
Run Code Online (Sandbox Code Playgroud)

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

我怎样才能做到这一点?

javascript arrays

1
推荐指数
1
解决办法
73
查看次数

标签 统计

arrays ×2

javascript ×2