Java script is an object oriented langugae, in other meaning we can say its an object based language.We must to work with objects when we learning or working with java script.In this topic we learn about working on objects by using strings, because everything in java script is an object,so it can be a string or a function or a datatype. Method of objects is very easy to learn because we also live in an object oriented world, whoever we see everthing is an object.
There are two parts of objects.
For understanding deeply about objects we take an example here: Let take an example of a chair. If a chair is an object than it's color, legs, hands,rest-back and seating area all are properties.Now what about methods? This chair have weels so it can move, it can be round up and also can lean back its all the actions can do by chair are methods of chair object.It's very easy to understand, is't it?
var myString = "My name is ankit kalra",
length = myString.length,
position = myString.indexOf("a"),
position1 = myString.indexOf("a",position+1),
position2 = myString.indexOf("a",position1+1);
console.log(length); //22
console.log(position); //4
console.log(position1); //11
console.log(position2); //18
var myString = "My name is ankit kalra";
var position = myString.lastIndexOf("a"),
position1 = myString.lastIndexOf("a",position-1),
position2 = myString.lastIndexOf("a",position1-1),
position3 = myString.lastIndexOf("a",position2-1);
console.log(position); //21
console.log(position1); //18
console.log(position2); //11
console.log(position3); //4
var myString = "My name is ankit kalra";
var position = myString.substr(0,2); //Show positon starts with 0 and than show till 2 chars
console.log(position); //my
//we can do also this by using with both function indexOf and substr
var position = myString.indexOf("n"); //starts with n and show till index position no 4
var position = myString.substr(position,4); //name
console.log(position); //name
var myString = "My name is ankit kalra";
var newString = myString.replace("ankit kalra","Kalra Ankit");
console.log(newString); //My name is kalra ankit.
var myString = "My name is ankit kalra."
var lowercase = myString.toLowerCase();
console.log(lowercase); //my name is ankit kalra.
var uppercase = myString.toUpperCase();
console.log(uppercase); //MY NAME IS ANKIT KALRA.