1

So obviously you can split a string into an array, like this:

var arrayOfStrings = originalString.split(' ');

But is it possible to somehow easily create an array of two splits?

Eg:

var arrayOfStrings = originalString.split(' ') && secondString.split(' ')

Obviously the above is pseudo code and not valid

3 Answers 3

8

You can do something like this

originalString.split(' ').concat(secondString.split(' '))

For reference - Array concat

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

Comments

4

Yes, with Array#concat

The concat() method returns a new array comprised of the array on which it is called joined with the array(s) and/or value(s) provided as arguments.

var arrayOfStrings = originalString.split(' ').concat(secondString.split(' '));

Comments

1

just use contact() method

originalString.split(' ').concat(secondString.split(' '))

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.