简体   繁体   中英

filtering out elements from an array based on second array in javascript

I have two following arrays

1) ['data/proxies/AuthDecoder/1/AuthDecoder.zip',
  'data/proxies/JSONP/1/JSONP.zip',
  'data/proxies/XMLP/1/XMLP.zip',
  'data/proxies/accessControl/1/accessControl.zip']

2) ['AuthDecoder', 'JSONP', 'XMLP',]

how do I filter out the first array so that the first array only contains those elements that also have a match in second array. The name of the proxy (with .zip extension) should match in both arrays.

So after the filtering, first array should look like

['data/proxies/AuthDecoder/1/AuthDecoder.zip',
  'data/proxies/JSONP/1/JSONP.zip',
  'data/proxies/XMLP/1/XMLP.zip',
]

Use Regex for the same

var str = "The rain in SPAIN stays mainly in the plain"; 
var res = str.match(/Spain/i);
document.getElementById("demo").innerHTML = res;

write string to be matched between '/' and then followed by modifier

  1. i is case insensitive
  2. g is global search
  3. m is used in multi-line search

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM