How to check if a string ends with a number in Node.js

1 Answer

0 votes
function stringEndsWithNumber(str) {
    return /[0-9]+$/.test(str);
}
 
console.log(stringEndsWithNumber('node.js 2022 2023 pro 2024')); 
console.log(stringEndsWithNumber('22F')); 
console.log(stringEndsWithNumber('PI3.14')); 





/*
run:
 
rue
false
true
 
*/

 



answered Jun 6, 2022 by avibootz

Related questions

...