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

Published: 11 March 2020
on channel: 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


On this page of the site you can watch the video online JavaScript Tutorial for Beginners - Part 16 | JavaScript String Methods | Learn Web Technologies with a duration of hours minute second in good quality, which was uploaded by the user Learn Web Technologies 11 March 2020, share the link with friends and acquaintances, this video has already been watched 40 times on youtube and it was liked by 2 viewers. Enjoy your viewing!