简体   繁体   中英

Javascript Get all number from array

From Array get only number into a new array or a string

var fetchMIDarray = [
  'Corp: nameofthecompany (345961663886)',
  'Chain: somerandomname (372395416889)'
]

except result for new array should be:

var fetchnumber =['345961663886','372395416889']

I know how this works for the string but unable to do same for array code sinppet for string.

 var midname='Corp: Best Buy ApplePay/Partsearch (345961663886)'; var matches2 = midname.match(/\d+/); console.log(matches2);

You can use Array#map .

 let arr = ['Corp: nameofthecompany (345961663886)', 'Chain: somerandomname (372395416889)']; let res = arr.map(x => x.match(/\d+/)[0]); console.log(res);

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