"2+3-8*5"
2
3
8
5
how to split this string and save different variable
"2+3-8*5"
2
3
8
5
how to split this string and save different variable
Here you can split your string into an array for multiple delimiters.
var strVal = "2+3-8*5";
var resp = strVal.split(/(?:\+|\-|\*)/);
console.log("Resp: " , resp);
@Gufran solution is great with regex. If you don't want to use regex you can use isNaN
with loop.
var str = "2+3-8*5";
var result = [];
for (var i = 0; i < str.length; i++) {
if (!isNaN(parseInt(str.charAt(i), 10))) {
result.push(str.charAt(i));
}
}
console.log(result);