GoConqr has a new look! Let us know what you think.

Module 3 of 9 · Media

The length property and the split method

Kostas Diakogiannis

The length property and the split method

String methods and properties

Strings can have methods and properties exactly like objects. 

One of the commonest properties is the length property who returns the length of a string and how many characters this string is comprised of.

Another important method is the  split method. That splits actually a string into a smaller strings, and then it puts them as elements into an array. The new array is comprised of string elements and you can work individually with every substring. Split is a method, that means that you can also pass an argument and specify every WHICH character occurrence you want  to split your main string.

For example if you have a string like: let sentence = 'this sentence is nonsense',

sentence.split('') // Splits every single character into an array. ['t', 'h', 'i', 's', ' ', 's', 'e', 'n', 't'] etc.

sentence.split(' ') (with a space inside the argument. Splits every time it finds a space. So we end up with something like. ['this', 'sentence', 'is', 'nonsense'].

 

Find out all methods for strings here.

Instructions

You must submit an attempt for this quiz to progress. You can submit it after the last question.

Go to the chosen module

Feedback

What is it about?

What do you think of the new look?

How do you like it?