Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array value needs to Text

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);
like image 945
Arunkumar Avatar asked Jun 21 '26 00:06

Arunkumar


1 Answers

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, '');
});
like image 117
Ja͢ck Avatar answered Jun 23 '26 13:06

Ja͢ck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!