Reputation: 1023
I think this question should be an easy one. I use a regex expression which, actually is:
str_pow = str_input.match(/(?:x)[^][+-]?\d{1,4}\s/g);
The problem lays in that I need only numbers, though they're still of string type(don't think about this), but not this part x^. Currently the how str_pow looks like is this
This means two things: I've to either edit my regex mask, or to find a way to cut the first two "x^" characters of for each element i of the array. Can you help me to do this, because I tried to slice but it was an unsuccessful experiment.
Upvotes: 0
Views: 56
Reputation: 163362
You can loop the array:
var a = ["x^5 ", "x^4 ", "x^2 ", "x^1 "];
for(var i = 0; i< a.length; i++) {
a[i] = parseInt(a[i].substring(2, a[i].length).trim(), 10);
}
console.log(a);
Upvotes: 2