Skip to main content

Command Palette

Search for a command to run...

Working WIth JavaScript Arrays Pt 3.

Published
1 min read
Working WIth JavaScript Arrays Pt 3.
A

Software Engineer currently working for Quantelux

34 year old Michigander, who loves the outdoors, loves staying active, loves programming, and anything wrapped in a tortilla.

My blog focuses on the the many varieties of knowledge I've picked up along the way in my developer journey.

Often in JavaScript you'll come across big long strings, that you'll more than likely want to separate certain items out into a more useful form, so then you can display them differently. Like a table for instance.

To do such an action, we can use the method, split(). Split takes a single parameter, which is the character you want to separate the string at, puts these substrings into an array, then returns the array. Let's play around with it.

1. First we create a string.

image.png

2. Next, we'll split it at every comma.

image.png

3. Lastly, we can find the length of the new array, and receive some items from it.

image.png

4. You can do the opposite of .split(), by using the .join() method.

image.png

5. One of the other ways of converting an array to a string, is using the *.toString()* method.

The .toString() method is more simple than the .join() method. It doesn't take a parameter. But, it is more limiting to use. With the .join() method, you can specify different separators, whereas with .toString() method, it always uses a comma.

image.png

O

Interested

1

More from this blog

Aaron Bush's Blog

11 posts

Software Engineer at Quantelux I love science, technology, puzzle-solving, and coding. When I'm not on my laptop working, I'll be skateboarding, snowboarding, or out in the woods.