One, String type
1. Use IndexOf () to position the first occurrence of a specified character in a string.
var str= "Hello world!"
document.write (Str.indexof ("Hello") + "<br/>") 0
document.write (Str.indexof ("World") + "<br/>")-1
document.write (Str.indexof ("World")) 6
2. Use Match () to find a specific character in the string and, if found, return the character.
var str= "Hello world!"
document.write (Str.match ("World") + "<br/>") World
document.write (Str.match ("World") + "<br/>") null
document.write (Str.match ("worlld") + "<br/>") null
document.write (Str.match ("world!")) world!
3. Use the Replace () method to replace characters with some characters in a string.
var str= "Visit microsoft!"
document.write (Str.replace (/microsoft/, "W3school")) Visit w3school!
II, Json.parse () and Json.stringify ()
1.parse is used to parse a JSON object from a string, such as
var str = ' {' name ': ' Huangxiaojian ', ' age ': ' 23 '} '
Json.parse (str)
Results:
Object
Age: "All"
name: "Huangxiaojian"
__proto__: Object
Note: Single quotes are written in {}, each property name must be in double quotation marks, or an exception will be thrown.
2.stringify () is used to parse out a string from an object, such as
var a = {A:1,b:2}
Json.stringify (a)
Results:
"{" A ": 1," B ": 2}"
JavaScript knowledge points