JavaScript String.split and Array.join

Sharing buttons:

something that frequently happens in web

development is manipulation of data

converting between different data types

in particular moving between strings and

arrays so you may take something that

somebody is typed and you want to split

it up into individual words for get the

individual characters so that you can do

some testing on that data or conversion

of that data so we will look at these

two methods the array method join on the

string method split if you want to

convert from a string to an array you

would call the split method this will

take your entire screen and split it

based on what are the youth court the

inside of here is the argument if you

want to convert from an array to a

string you called joint and again you

say this is what I want you to put in

between each of the elements of the

array when you combine them to make a

string so really is this example

sentence here a little my name is inigo


and i want to split this up into

individual words so I'm going to be

creating an array I'm going to call it

words and inside of here we're going to

call sentence and then we're going to

call it because sentence this is strings

so I have to use this term now you can

see here the autocomplete it's a string

pattern number limit so I can put inside

of here just a string to say break it

one of you find this or I can actually

use a regular expression pattern to

define I'm just going to be using a

simple spring which is if this example

sugar so I'm going to split it whatever

I find a space like this out winds go

off another example is here and go to 1d

what charge as well

oh yeah so you can see that words is an

array denoted by the square brackets and

it has the individual items hello my

name is inigo montoya now because words

is an array it means that we can use

array methods on it such as sort and it

comes the result of all this is going to

be the array that's placed inside of

here it means at the end I could if I

wanted I've run away method there we go

now we have a sorted array so it avoids

hello in your employer is my name H I oh


yes it's using team Unicode values for

you so is asking values for each of

these letters so because these are in

capitals they come before the lowercase

that's why we don't have exactly what we

wanted here we have to convert into

those words into lowercase or each of

the words into uppercase before we do

this so to the people that I reread but

not to work the other example I want to

show you is something that fairly common

the used sentence going to split it

again but instead of putting say I use

this name it's going to take this chunk

of the sentence remove it and it's going

to have this as the first element in my

way and everything from this point to

the M including the spaces would become

the second part just to demonstrate that

that is actually what is being done over

the hello my space space is minimal air

so it removed name and the spaces sorry

not the spaces I decide if I put the

spaces inside of here they should be

unique as well so all my focus

is like space in front of it wasn't what

I wanted to show you that was just a

demonstrative what support is actually

doing in the fact that you can put

whatever you want inside okay I'm gonna

put nothing just an empty string by

doing that I'm actually going to be

splitting it every single character so

hopefully soon with character between

each character there is nothing that's

what I'm spreading it on nothing so

we're getting away with every single

character being an individual element

inside of you all right so that is the

string method split the array method

join just does the reverse so I could

say let infinitive variable for words

that is the array of here however you

the motive is my name and I'm going to

call John again inside of here for put

nothing will be nothing it'll just stick

them all together a tight spaces will I

put a space between them I'm getting

back to the original sentence you're

physically fit of space here and here

and here and here and here I've called

the vertical hyphenated because I don't

have it to put a hyphen in there just to

show that it would be something

different variable hyphenated good oh I

think vinegar - material - is - my -

length okay that's working I'm going to

comment out the choice just to clear up

some space

will these words may be hyphenated and

just to show you can do the same thing

as we were doing with split here I can

combine everything together with no

spaces in between sort of city roads

joined with nothing

oh yeah there's a sentence with no

spaces in between alright last example I

want to show is just taking the original

sentence I want to split it into

individual words I'm gonna sort the

sentence by the order and then I'm going

to join them back together with spaces

so basically I'm just an opening i

recording a sentence of these are going

to be rearranged sort of is love neither

Montoya is my name it is that the fast

you order or we could convert it to the

other case or out the case into that

book so as to keep it short and sweet

so we're going to split on every space

to get the six individual elements then

we're going to call sort to sort them

Bobby asked the order and then we're

going to rejoin them with a space in

between and we'll put all this into a

variable console.log another go so the

three capitalized ones first the three

lower case ones last h5m I femme n so it

took the original sentence split apart

into individual words so all the spaces

will remove we're just left with the

words themselves we've sort of the words

non-ascii order then we joined them back

together putting spaces back in between

them and that's where you put it so you

can tell because there's no square

brackets that this is just one

individual string that the words have

been rearranged by this one month ago a

nasty spring split method and the away

join method