0

For a simple function, how can I return an array with a string as a parameter? I want the array to split the string at the spaces so it returns as [" ", " "].

I tried using the split method split(" ", 2) but it didn't seem to work.

1
  • 1
    What does the string look like to begin with, and what are you expecting, surely not an array with two empty spaces? Commented Nov 29, 2013 at 19:19

1 Answer 1

2
var arr = str.split(" ");

You don't need to add 2 after.

The 2 limit the number of value in the array, if you want to split the string without a max, then take out the 2.

The split will "split" the string with " ", if you want to split with other character, replace the space by what you need.

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

Comments

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.