JavaScript Split and Join: Cut and Combine Strings
Use JavaScript split and join to turn strings into arrays and arrays back into strings. See clear examples you can apply right away.

When working with JavaScript, we sometimes want to split long sentences into pieces and use them inside an array. In that case, we use the split function JavaScript provides for us. Let’s look at this with an example like the following.
var metin = "Bu akşam için bir plan yaptım.";
//We'll split the text above using the space character, which is why we put a space between the two quotes.
var sonuc = metin.split(" ");
console.log(sonuc);
//The console output will look like this. We now have an array, and we can use this array however we like.
["Bu","akşam","için","bir","plan","yaptım."]
Now we’ve split the sentence used in the example above into parts, but let’s join this split array back together with a – sign between the parts. JavaScript gives us the join function for this, so let’s use it too.
Diziyi bir değişkene tanımlıyoruz .
var sonuc = ["Bu","akşam","için","bir","plan","yaptım."];
//Now we write the character to use when joining the sonuc array with the join function.
var birlestir = sonuc.join("-");
//Let's print it to the console
console.log(birlestir);
// The output will be as follows.
Bu-akşam-için-bir-plan-yaptım.
Share it if it helped


