string.split array.join
by Ken Sprague
JavaScript
//string split and array joiin methods
//converting strings to arrays and arrays to strings
//string to array str.split();
//array to string arr.join();
let sentence = "Hello my name is Batman";
let words = sentence.split(" ");
console.log(words);
let chars = sentence.split("");
console.log(chars);
let hyphenated = words.join("-");
console.log(hyphenated);
let oneWord = words.join("");
console.log(oneWord);
let x = sentence.split(" ").sort().join(" ");
console.log(x);