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

asked Feb 23, 2016 at 16:43

3 Answers 3

8

You can do something like this

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

For reference - Array concat

answered Feb 23, 2016 at 16:45
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(' '));
answered Feb 23, 2016 at 16:45

Comments

1

just use contact() method

originalString.split(' ').concat(secondString.split(' '))
answered Feb 23, 2016 at 16:51

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.