Delete all elements in the array that start with a specific row

Hi, let's say that I have such an array in javascript:

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

How to remove all lines from my array starting with ftp_

thanks

+4
source share
3 answers

Just use Array.filter :

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

Edit: to support IE9 you can use jQuery.grep :

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

Use regex:

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

use temp array to store the desired string. for (i = 0; i <are.length; i + =) {if (! arr [i] .startesWith ('FTP _')) {Tempo [J] = arr [I]; J ++:} arr = pace; }

0
source

Source: https://habr.com/ru/post/1499679/


All Articles