删除数组中以特定字符串开头的所有项目

嗨,让我们说我在javascript中有这样的数组:

var arr = ["ftp_text_1", "abc_text_2", "ftp_text_3"]; 

如何从我的数组中以ftp_开头的所有字符串中删除

谢谢

只需使用Array.filter

 arr = arr.filter(function (item) { return item.indexOf("ftp_") !== 0; }); 

编辑:对于IE9-支持,您可以使用jQuery.grep

 arr = $.grep(arr, function (item) { return item.indexOf("ftp_") !== 0; }); 

使用正则表达式:

 $.each(arr, function (index, value) { if (value.match("^ftp_")) { arr.splice(index, 1); } }); 

使用temp数组来存储所需的字符串。 for(i = 0; i