Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the string attribute in js

Shulou Source: shulou.com Published: 2022-06-01 10:29:01 10月26日 Update

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

Tags: Character string array attribute number position content method more article index good practical variable article look knowledge first time length reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB MySQL vpn OPPO Reno Xiaomi