Strings containing numeric parts in ascending order
/**
* Extracts the numeric part from a given string.
* @param {string} str - The input string from which to extract the numeric part.
* @returns {string} The numeric part of the input string. If no numeric part is found, an empty string is returned.
*/
function getNumericPart(str) {
let numericPart = "";
for (let i = 0; i < str.length; i++) {
if (!isNaN(parseInt(str[i]))) {
numericPart += str[i];
} else {
// If a non-numeric character is encountered, break the loop
break;
}
}
return numericPart;
}OR USE RegEx with .match()
.match()Last updated