0

If I had a string with three values that is delimited by spaces, now I want to store these three values in three variables or maybe an array, how to do?

2 Answers 2

2

Use split().

For example:

var variables = delimited_string.split(/\s+/);

If you know it is separated by a single space, avoid using a regular expression with the following:

var variables = delimited_string.split(' ');
Sign up to request clarification or add additional context in comments.

Comments

0

Got it: I use String.split(pattern)

var str = "I am confused".split(/\s/g)

2 Comments

Are you answering your own question?
The g modifier is unnecessary.

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.