I have a Array like
text=['2','2<sup>2</sup>','3<sup>10</sup>'.......];
I want result like this
text=['2','22','310'......];
How can i get This using javascript
var optionTxt = (xmlDoc.getElementsByTagName('Option')[i].textContent ? xmlDoc.getElementsByTagName('Option')[i].textContent : xmlDoc.getElementsByTagName('Option')[i].text);
optionList[i] = $.trim(optionTxt);
You can use a .map operation for that and replace any non-digit with nothing using .replace():
text.map(function(item) {
return item.replace(/\D/g, '');
});
Since you're using jQuery you might also use their .map instead to fully benefit from cross (old) browser compatibility:
$.map(text, function(item) {
return item.replace(/\D/g, '');
});
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