JavaScript Tutorial for Beginners - Part 16 | JavaScript String Methods | Learn Web Technologies

Veröffentlicht am: 11 März 2020
auf dem Kanal: Learn Web Technologies
40
2

CSS Playlist
   • CSS Tutorial for Beginners  

HTML Playlist
   • Html tutorial for beginners  

Sign up for my newsletter to receive weekly updates
http://bit.ly/2RRFktj

Join our facebook page
bit.ly/2OKQYV7

JavaScript String Methods
String methods help you to work with strings.

String Methods and Properties
Primitive values, like "John Doe", cannot have properties or methods (because they are not objects).

But with JavaScript, methods and properties are also available to primitive values, because JavaScript treats primitive values as objects when executing methods and properties.
Finding a String in a String
The indexOf() method returns the index of (the position of) the first occurrence of a specified text in a string:

JavaScript counts positions from zero.
0 is the first position in a string, 1 is the second, 2 is the third ...

The lastIndexOf() method returns the index of the last occurrence of a specified text in a string:

Both indexOf(), and lastIndexOf() return -1 if the text is not found.

Both methods accept a second parameter as the starting position for the search:

The lastIndexOf() methods searches backwards (from the end to the beginning), meaning: if the second parameter is 15, the search starts at position 15, and searches to the beginning of the string.

Searching for a String in a String
The search() method searches a string for a specified value and returns the position of the match:

Did you Noticed?
The two methods, indexOf() and search(), are equal?
They accept the same arguments (parameters), and return the same value?

The two methods are NOT equal. These are the differences:
The search() method cannot take a second start position argument.
The indexOf() method cannot take powerful search values (regular expressions).
----------------------------------------------------------------------------------------------------------------
#LearnWebTechnologies #Javascript #JavascriptTutorialForBeginners #JavascriptPlaylist


Auf dieser Seite können Sie das Online-Video JavaScript Tutorial for Beginners - Part 16 | JavaScript String Methods | Learn Web Technologies mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Learn Web Technologies 11 März 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 40 Mal angesehen und es wurde von 2 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!