Reputation: 85653
var str = 'asdf234awe324wese34'; // or string -> '23asdre34ere' or something
numbers should be in an array like this:
var strArr = [234,324,34]; // if string or -> [23,34] or something
might be answer?
var a = '23wer234sdf45';
var reg = /\d+/g;
var store = a.match(reg);
//alert(store[2]);//alerts 45
But now how can I store it in an array?
var storeArray = []; //insert matched numbers here
So that I could use it by calling apply() method later in my project....
no such project, just to learning for fun
Upvotes: 1
Views: 54
Reputation: 139
You can use the substring method
.
int str = 'asdf234awe324wese34';
var storeArray = [];
storeArray[0] = str.subString(4,7);
storeArray[1] = str.subString(10,13);
storeArray[2] = str.subString(17,19);
Upvotes: 0
Reputation: 26598
var a = '23wer234sdf45';
var reg = /\d+/g;
var store = a.match(reg);
console.log(store[0]);
console.log(store[1]);
console.log(store[2]);
Like everyone else said it's already an array, but in case not then:
var storeArray = [store[0], store[1], store[2]];
Upvotes: 1