How to use the string attribute in js
This article is about how to use the string attribute in js. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
/ / define variables
Var S1 = "this is javascript"
/ / get the length of the string
Console.info (s1.length)
/ / get the character with index position 3
Console.info (s1.charAt (3))
/ / determine which index position of a character appears for the first time in a string
Console.info (s1.indexOf ("I"))
/ / intercept the string to get the string in the string
Var subs1 = s1.substring (3pc6)
Console.info (subs1)
/ / split the string into an array
Var sArray = s1.split ("")
/ / print the split array
For (var i in sArray) {
Console.info (Array [I])
}
/ / concatenate an array into a string
S2 = sArray.join ("")
Console.info (S2)
/ / practice
/ / the first method
/ / var words = ["America", "Greece", "Britain", "Canada", "China", "Egypt"]
/ / var count = 0
/ / for (I = 0; I