This document describes various string methods in JavaScript including charAt(), charCodeAt(), concat(), fromCharCode(), indexOf(), lastIndexOf(), match(), replace(), search(), slice(), split(), substr(), substring(), toLowerCase(), toUpperCase(), trim(), valueOf(), anchor(), big(), and more formatting methods. It provides examples of each method, demonstrating how to call the method and what it returns.
6. indexOf()
var str = "Hello world, welcome to the
universe.";
var n = str.indexOf("welcome");
// 13
7. lastIndexOf()
var str = "Hello planet earth, you are a
great planet.";
var n = str.lastIndexOf("planet");
// 36
8. match()
var str = "The rain in SPAIN stays mainly
in the plain";
var res0 = str.match(/ain/g); //global
var res1 = str.match(/ain/gi); //global
ignore case
// ain,ain,ain
// ain,AIN,ain,ain
9. replace
var str = "Visit Microsoft!";
var res = str.replace("Microsoft", “Apple");
// Visit Apple
10. Search()
var str = "Visit Apple!";
var n = str.search(“Apple");
// 6
11. slice()
var str = "Hello world!";
var res = str.slice(1,5);
// ello
12. split()
var str = "How are you doing today?";
var res = str.split(" ");
// How,are,you,doing,today? (array)
13. substr()
var str = "Hello world!";
var res = str.substr(1, 4)
//ello
// desde el 1º 4 caracteres
14. substring()
var str = "Hello world!";
var res = str.substring(1, 4);
// ell
// desde el 1º al 4º caracter sin incluirlo.