I have an Array:
arr1 = ["gbt100", "gbt1130", "gbt12300", "gbt104230"]
How can I remove the "gbt" string from each of the elements?
You can use the map method by passing a callback function as an argument which is applied for every item from your given array.
Also, you need to use replace method in order to remove the gbt string.
arr1 = ["gbt100", "gbt1130", "gbt12300", "gbt104230"]
arr1 = arr1.map(elem => elem.replace("gbt", ""));
console.log(arr1);
Another approach is to pass a regex as the first argument for the replace method.
arr1 = ["gbt100", "gbt1130", "gbt12300", "gbt104230"]
arr1 = arr1.map(elem => elem.replace(/gbt/g, ""));
console.log(arr1);
If you want to remove all the alphabetical chars just change the regex expression inside replace method.
arr1 = arr1.map(elem => elem.replace(/[a-zA-Z]/g, ""));
[a-zA-Z] instead of gbt to replace all alphabets
Arraymethods. What have you tried?arr1.join(',').replace(/gbt/g, '').split(',')map, notfilter, notforEach.