Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the string attribute in js

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report