GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Modul 3 von 9 · Medien

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.

Anleitung

Um im Kurs weiterzukommen, sende einen Versuch dieses Quiz ab. Du kannst ihn nach der letzten Frage absenden.

Zum gewählten Modul

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck