prisskreative
11/11/2014 - 9:12 PM

Methods

Methods

/* Methods
There are many methods that you can call on JavaScript to transform or get information about the string. 
To get information of the string - EX : lenght - toLowerCase - toUpperCase - substr - charAt - indexOf */

var part1 = "Hello";
var part2 = "World";

var whole = "Hello " + "World"; 
var whole = part1 + part2; //same as above

console.log(whole);

var length = whole.length;
console.log(whole, length);

Hello World  12

//String that we want to find in a whole
var index = indexOf("World");
console.log(index);

6 // word appaer after the 6 character

-1 //  word doesn't exist on the string


if(whole.indexOf("W") !== -1){
	console.log("W exist in string")
}else{
	console.log("W does not exist");
}


console.log(whole.charAt(2))// show second character on the string  = log


Hello Worl d
1234567891011

var world = whole.substr(6,5); // whole.substr(star, lenght)
console.log(whole);
World


var world = whole.toLowerCase(); 
console.log(whole);
HELLO WORLD