Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Foundations Arrays Methods: Part 3

The "split" method?

At around 8:20 Jim mentions the "split" method like it was covered previously. Where was this mentioned?

3 Answers

Andrew Barrette
PLUS
Andrew Barrette
Courses Plus Student 2,219 Points

Split is a String method used to break up Strings into separate (smaller) Strings which are returned as an array of Strings.

It takes two parameters. The first is the char or String you want the original String to be broken at. The second (optional) parameter is how many times you want the String broken.

e.g.

  var sentence = "Data is not information, information is not knowledge, knowledge is not understanding, and understanding is not wisdom.";
  sentence.split(","); 
  // returns ["Data is not information", " information is not knowledge", " knowledge is not understanding", " and understanding is not wisdom."]

  sentence.split("is not ", 3);
  // returns ["Data ", "information, information ", "knowledge, knowledge ", "understanding, and understanding is not wisdom."]

W3 Schools has a pretty good explanation with editable examples. In fact, W3 Schools has a complete Javascript Reference that I've found highly useful.

Thanks everyone. I was able to find what I needed. Just wanted to make sure I didn't miss something in the video since split was referenced like it was already covered, but I hadn't seen it.

Thank you for asking Jason, I also notice the omission of an example of a "split" in the video. The fact that is being answered here, prevents me from trying to find out if I missed in in a previous video.

Rich Donnellan
MOD
Rich Donnellan
Treehouse Moderator 27,671 Points

Jason,

Personally, I gave up on the JavaScript Foundations course (brutal to watch), so I can't answer your question specifically. You can find a comprehensive reference on the split method over at the Mozilla Developer Network.

Check it out here!

-Rich