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
j_d
3,12010 gold badges58 silver badges97 bronze badges
3 Answers 3
You can do something like this
originalString.split(' ').concat(secondString.split(' '))
For reference - Array concat
answered Feb 23, 2016 at 16:45
Nikhil Aggarwal
28.5k4 gold badges47 silver badges61 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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
Nina Scholz
388k26 gold badges367 silver badges417 bronze badges
Comments
lang-js