Short version of the common methods for Javascript string objects

  • 2020-03-30 03:28:58
  • OfStack

var a = "abcDEfGgdefg32asdf38";
document.write(" The original :"+a+"<br />")
document.write(" The bold :"+a.bold()+"<br />");
document.write(" large :"+a.big()+"<br />");
document.write(" italics :"+a.italics()+"<br />");
document.write(" Delete the line :"+a.strike()+"<br />");
document.write(" The font size :"+a.fontsize(10)+"<br />");
document.write(" The font color :"+a.fontcolor("#ff0000")+"<br />");
document.write(" superscript :"+a.sup()+"<br />");
document.write(" The subscript :"+a.sub()+"<br />");
document.write(" A capital :"+a.toUpperCase()+"<br />");
document.write(" A capital :"+a.toLowerCase()+"<br />");
document.write(" Return index character :"+a.charAt(3)+"<br />");//This should be "D"
document.write(" Returns the index :"+a.indexOf("f")+"<br />");//This is going to be 5
document.write(" Returns the index ( The reverse lookup ):"+a.lastIndexOf("f")+"<br />");//This is going to be 9
document.write(" Find string :"+a.search("f")+"<br />");//This is going to be 5 , and indexOf The same 
document.write(" Substitution string :"+a.replace("a","A")+"<br />");//Replace the a in the string with an a
document.write(" Returns the substring :"+a.slice(1,3)+"<br />");//It should be BC, return substrings from index 1 to 3-1
document.write(" Split string :"+a.split("D").toString()+"<br />");//Using D as the separator, split the string and return the array
document.write(" Returns the substring :"+a.substr(1,2)+"<br />");//Returns a substring, starting at index 1, of length 2, which in this case is BC
document.write(" Returns the substring :"+a.substring(1,3)+"<br />");//Like sclice(), returns a substring of indexes 1 through 3-1
document.write(" matching :"+a.match(/d+/)+"<br />");// Regular match, return the result of the match, here is 32


Related articles: