JavaScript array splice

前端 未结 2 1745
长情又很酷
长情又很酷 2021-01-23 04:56

Hello StackOverflow community!

At the moment I am completly stuck with my code, have try different ways to remove a value from array when picked, I know I have to use sp

2条回答
  •  悲&欢浪女
    2021-01-23 05:54

    First, put the random-number in a seperate variable

    var rnd = Math.floor(Math.random()*cars.length);
    var rand = cars[rnd];
    

    Then remove that specific item from the array

    cars.splice(rnd, 1);
    

    Cheers R

提交回复
热议问题