The code for this lecture is available on Github
Consider this string
let fruits = 'Mango, Peach, Banana';
What if we want to separate out the fruits from this String i.e. get an array of fruits.
To do this we can use the split() method.
In order to use split() we need to pass the character which needs to be used to perform the split.
let fruitArray = fruits.split(','); fruitArray // ['Mango', 'Peach', 'Banana'] fruitArray // Mango
To combine all the array elements back, so that we can get a String, we can use the join() method.
fruitArray.join('-') // 'Mango-Peach-Banana'
Alternatively we can use the toString() method.
How to add and remove elements to or from an Array?
To add or remove an element at the end of the Array you can use push() and pop()
push() lets us add an element to the end of the Array.
pop() lets us remove an element from the end of the Array.
Similarly, to add or remove an element at the start of the Array you can use unshift() and shift()