| Viewed 113 times

How to check if the string has numbers in Javascript


I need a function that takes an array of strings and returns an array with only the strings that have numbers in them. If there are no strings containing numbers, return an empty array.

1 Answer
Mohammad Qandeel
Answered
8

this function will return an array with only the strings that have numbers in them

function numInStr(arr) {
 return arr.filter(str => str.match(/[0-9]/) !== null);
}

 

 


Related Questions