remove string element from javascript array

前端 未结 4 1524
我在风中等你
我在风中等你 2020-12-20 15:03

can some one tell me how can i remove string element from an array i have google this and all i get is removing by index number

my example :

 var          


        
4条回答
  •  囚心锁ツ
    2020-12-20 15:43

    Since you're using jQuery

    myarray.splice($.inArray("abc", myarray), 1);

    EDIT If the item isn't in the array, this 'one-liner' will likely throw an error. Something a little better

    var index = $.inArray("abc", myarray);
    if (index>=0) myarray.splice(index, 1);
    

提交回复
热议问题