tags:

views:

329

answers:

2

Does anyone know how can I cut a string and then assign into an array with javascript? Example:

var string = "15;24;67;34;56";

I hope tp cut this string into below format and assign into the array:

a[0] = 15 a[1] = 24 a[2] = 67 a[3] = 34 a[3] = 56

+4  A: 

var a = string.split(';');

htw
A: 

string.split(";")

In this example, you'll end up with an extra array item at the end, though, so you'll want to handle that separately.

Aaron Boodman
No, the string was specified as "15;24;67;34;56"—there would be no extra array item at the end, as far as I am aware. If you're talking about the array indices the OP mentioned, I think that's a typo.
htw