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

2 Answers 2

5

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

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

Comments

0

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.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.