1

I need to convert a string with multiple numbers to an array in jQuery. My string is the one below:

var strVal = "901,235,342,421,345,745,544,324,445,123,232,986,345,678";
0

2 Answers 2

2

You don't need jquery for this

var strVal = "901,235,342,421,345,745,544,324,445,123,232,986,345,678";
var result = strVal.split(",").map(x=>+x);
console.log(result);

Sign up to request clarification or add additional context in comments.

Comments

2

You could use String.split with ',' and then Array#map with to Number converted values

var strVal = "901,235,342,421,345,745,544,324,445,123,232,986,345,678",
    numbers = strVal.split(',').map(Number);

console.log(numbers);
.as-console-wrapper { max-height: 100% !important; top: 0; }

1 Comment

Upvote for the CSS trick to make the console's view better, really nice!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.