Coding Challenge Cheat Sheet

While coding, it's better to have some tricks and methods handy

1. String to Array

str.split() // Split the string based on the type passed as an argument

const singleStr = "sandeep";

singleStr.split(); // ->    ["sandeep"]

singleStr.split(" "); // -> ["sandeep"]

singleStr.split(""); // ->  ["s","a","n","d","e","e","p"]


const spaceStr = "john doe";

spaceStr.split(); // ->    ["john doe"]         

spaceStr.split(" "); // -> ["john", "doe"]

spaceStr.split(""); // ->  ["j","o","h","n","","d","o","e"]


const commaStr = "jo,hn";

spaceStr.split(); // ->    ["jo,hn"]         

spaceStr.split(" "); // -> ["jo,hn"]

spaceStr.split(""); // ->  ["j","o",",","h","n"]

spaceStr.split(","); // ->  ["jo", "hn"]

2. Array to String

arr.join() // join the array based on argument passed

arr.toString() // converts array to string as it is

Last updated

Was this helpful?