In part 1 , we discussed about creation , conversion , comparison and String class and primitive string.
Reversing an string
Using split , reverse and join (popular method)
String.prototype.split(deliminator) : Split string into an array and parameter "" means split between each character.Eg -> "string".split('') // ['s' , 't' , 'r' , 'i' , 'n' , 'g']Array.prototype.reverse() : reverse the array.Eg -> ['A' , 'B' , 'C'].reverse() // ['C' , 'B' , 'A']Array.prototype.join(deliminator) : Joins the element in the Array together into a string. The "" parameter means a empty deliminator (i.e., the elements of the array are put next to each other)
reversing an array using spread operator
I prefer to use this method as it works for not only arrays and numbers but also for surrogate pairs. (“talk in upcoming session”)
[..."String"] is same as "String".split('')
custom reverse function
Sorting of Array lists using localeCompare()
Thanks a lot for your time, Leave a clap if you like it. I am very happy if you are reading this after first “String in JS part 1”.