.split() it up!
The javascipt .split() method is something I have implemented over and over in my relatively short programming journey thus far. This post…
The javascipt .split() method is something I have implemented over and over in my relatively short programming journey thus far. This post will go over what this simple but effective method does and how to use it.
The .split() method takes a string and splits it into an array, leaving the original string untouched.
const string = "Hello world"
console.log(string.split(""))
Console returns: //["H", "e", "l", "l","o", " ", "w","o","r","l","d"]Using (“”) as a seperator splits the string into an array or substrings of individual single characters. We can also use this method to split the string by word.
const string = "Hello world"
console.log(string.split(" "))
Console returns: //["Hello", "world"]The difference in syntax here is adding a space in the seperator (“ “). Once the string is split in into a sub-array, indiviual characters and words can be accessed via by their item number:
const string = "Hello world"
const wordSplit = string.split(" "))
console.log(wordSplit[0])
Console returns: // HelloI am aiming to write a more in depth post about accessing array items in the future.
Splitting a string is essential to solving many problems and create effective logic in many aspects of programming. I am in the process of building an anagram based word game (blog post to follow) and this method has been instrumental.
I have previously cloned the popular word game Wordle in React and manipulating strings was something that had to be done frequently.
wordle-clone-jamesrobertsutcliffe.vercel.app
Finally, I would reccomend taking a looking at the following kata on codewars and implementing the .split() method, it’s a great way to apply what has been discussed today:
WeIrD StRiNg CaSe
Write a function toWeirdCase (weirdcase in Ruby) that accepts a string, and returns the same string with all even…www.codewars.com
Follow me on github to keep up with my coding!
JamesRobertSutcliffe - Overview
A developer who is enthusiastic about building and learning everything programming related. Committed lifelong learner…github.com
Take a look a my previous post about CSS hovers to add sweet transitions to your front end.
CSS Hover Effects
CSS effects are a simple way to add interesting user interactivity to a page. When elements are hovered over, the syle…medium.com
Thanks very much for reading!
Please follow me on medium and Twitter for updates and new stories every week.




