javascript - Delete the array items which have lower specific value -
I want to change array1 to array2. The keyword is a test, test2,885, length. I want the keyword's next value (#?) To be the highest.
var array1 = ["# 4 # test # 4 # t # limited", "6 # test # 6 # 885 # restricted", "7 # test2 # 2 # 2 #" "8 # test2 # 4 # 3 # limited", "11 # 885 # 1 # tt #restricted", "15 # length # 1 # taw # restricted" "17 # 885 # 11 # t # limited"]; Var arrar2 = ["6 # Examination # 6 # 885 # Restricted", "8 # Examination # 2 # 4 # 3 #", "17 # 885 # 11 # T # Limited", "15 # Length # 1 # Restricted "];
Do you want it?
var array 1 = ["# 4 # exam # 4 # t # limited", "6 # exam # 6 # 885 #", restricted "# 7 # test2 # 2 # 2 # restricted", "8 # test2 # 4 # 3 # restricted", "11 # 885 # 1 # tt # restricted" "15 # length # 1 # taw # restricted" "17 # 885 # 11 # T # Limited "]; Var keyword = ["test", "test2", "885", "length"]; Var array 2 = []; For keywords Every (function (key) {var match = []; var regex = new RegExp ("\\ b" + key + "# (\\ d +)"); array1.for eca (function (value) {if ( Regex.test (value)} {matched.push ([parseInt (RegExp. $ 1), value]);}}); if (matched> length> gt; {matched.sort (function (a, B) {return B [0] - a [0];}); array 2.push (match [0] [1]);}}); Warning (array2);
Comments
Post a Comment