remove string element from javascript array

前端 未结 4 1555
我在风中等你
我在风中等你 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:41

    more simple solution

    var myarray = ["xyz" , "abc" , "def"]; 
    var removeMe = "abc";
    
    var theNewArray = myarray.filter(s => s !== removeMe);
    
    console.log(theNewArray); // will return ["xyz" , "def"]
    

提交回复
热议问题