
The test() method will return true if the string contains any letters and false otherwise.

Use the RegExp.test() method to check if a string contains any letters, e.g. The way it was originally written looks for '2,'.Īlso to reinforce what Klaus said, if you have control over the way the data is handled you may find it easier to store lists of values in an array. Check if a String contains any Letters in JavaScript. The value checked by topPage.indexOf() does not need the added comma. ES2015: includes(str, searchValue) returns true if searchValue is found anywhere within str, false otherwise. The only change was to remove the trailing comma from temp value - your comma delimited string does not end with a comma, so it could never find the last value.

While Klaus is correct that you are working with integers, they arrive at your code as a single string, so it's a valid question.
