Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

Working with arrays and strings

Strings can also work well with arrays.

If you want to take a string and split every letter into an array in order to work individually with all letters you can do it with the split method as we have seen.

Join method is the exact opposite. Is an ARRAY METHOD actually that unites all the elements of an array into a string. You can parameterize what is going to stand between every array element when the string unification takes place exactly the same way with a split, by adding something between every substring.

example: const fruits = ['Apple', 'Orange', 'Bananas']. If we put fruits.join('-') all elements will be unified in a single string with '-' between them. 

Final result: 'Apple-Orange-Bananas' 

Reverse is another action that can be taken in ARRAY to reverse the order of the elements inside it.  Returns the array in reversed order.

Let's see some case were we can used what we learned.

Reverse Join

Kostas Diakogiannis
Module by Kostas Diakogiannis, updated more than 1 year ago
No tags specified