Removing an element from an array specifying a value in Javascript

前端 未结 5 471
独厮守ぢ
独厮守ぢ 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:42

    You can jQuery's $.inArray and get rid of your $.each loop, and it works cross-browser (unlike Array.indexOf):

    var index = $.inArray("test2", ["test1", "test2", "test3"]); // 1
    

    (I realise your question is not tagged with 'jQuery', but you do mention that you're already using an $.each loop).

提交回复
热议问题