I have a bunch of strings that look like:
var uglystrings = ["ChipBagYAHSC","BlueToothNSJ"]
They all have a 2-5 capital letters at the end. I would like to remove the capital letters from the end using js but I am not sure what is the most efficient way? I cannot do substr
because they all will have a different number of capital letters at the end
Iterate the array using Array#map, and replace the uppercase letters of at the end of each string using a RegExp (regex101):
var uglystrings = ["ChipBagYAHSC","BlueToothNSJ"];
var result = uglystrings.map(function(str) {
return str.replace(/[A-Z]+$/, '');
});
console.log(result);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With