Removing an element from an array specifying a value in Javascript

前端 未结 5 481
独厮守ぢ
独厮守ぢ 2020-12-10 15:13

I have read this question:

Deleting array elements in JavaScript - delete vs splice

And it appears that both splice and delete require an index of the elemen

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-10 15:58

    var array = ["test1", "test2", "test3"];
    array.splice(array.indexOf("test2"), 1);
    

    indexOf (source):
    Returns the first index at which a given element can be found in the array, or -1 if it is not present.

提交回复
热议问题