JavaScript String Methods Functions Example
There are Following List of JavaScript String Functions Example.
- String Length.
- indexOf() :Finding a String using JavaScript.
- lastIndexOf() :Finding a String using JavaScript.
- search() :Searching for a String using JavaScript.
- slice() Method with Example.
- substring() Method with Example.
- Replacing String replace(): Method with Example.
- Converting to Upper Case Example.
- Converting to Lower Case Example.
- The concat(): Method with Example.
- split() : Method Convert a String to an Array Example.
String Length
var strval = "pakainfofreedevelopedbyangularjskinganddsppatel"; var result = strval.length; console.log(result); alert(result);
indexOf() :Finding a String using JavaScript
var strvalue = "I learn Angularjs"; alert( strvalue.indexOf("I learn") ); // zero (ex.first character position index start) alert( strvalue.indexOf("learn") ); // 2 var strvalue = "I learn Angularjs"; alert( strvalue.indexOf("pakainfo") ); // Not found: The returns -1
lastIndexOf() :Finding a String using JavaScript
var strvalue = "I learn Angularjs for Pakainfo.com"; document.write(strvalue.lastIndexOf('learn')); document.write(strvalue.lastIndexOf('com')); document.write(strvalue.lastIndexOf('for'));
search() :Searching for a String using JavaScript
var strvalue = "I learn Angularjs for Pakainfo.com"; var result = strvalue.search("Angularjs"); console.log(result); alert(result);
slice() Method with Example
var strval = "pakainfo, pakainfo example, pakainfo"; var result = strval.slice(7,14); console.log(result); alert(result);
substring() Method with Example
var strval = "pakainfo, pakainfo example, pakainfo"; var result = strval.substring(7,14); console.log(result); alert(result);
substr() Method with Example
var strval = "pakainfo, pakainfo example, pakainfo"; var result = strval.substr(7,6); console.log(result); alert(result);
Replacing String replace(): Method with Example
var strval = "pakainfo, pakainfo example, pakainfo"; var result = strval.replace('pakainfo','angularking'); console.log(result); alert(result);
Converting to Upper Case
var strvalue = "Hello World! - welcome to Angularjs"; var result = strvalue.toUpperCase(); console.log(result); alert(result);
Converting to Lower Case
var strvalue = "Hello World! - welcome to Angularjs"; var result = strvalue.toLowerCase(); console.log(result); alert(result);
The concat(): Method with Example
var strval1 = "Hello World!"; var strval2 = "welcome to Angularjs"; result = strval1.concat(" ", strval2); console.log(result); alert(result);
split() : Method Convert a String to an Array Example
var strval = "a,n,g,u,l,a,r,j,s"; var result = strval.split(","); console.log(result[0]); console.log(result[1]); console.log(result[2]); alert(result[1]);