This article mainly introduces the common methods of String in Javascript, and analyzes the common character conversion, truncation, and segmentation techniques of String, for more information about how to use String in Javascript, see the following example. Share it with you for your reference. The details are as follows:
// Length attribute: obtains the number of characters in a string. Var s = 'Love is like a gust of wind'; alert (s. length); // charAt (index) method: Gets the character at the specified index position. The index starts from 0. var s1 = 'I don't miss you anymore'; alert (s1.charAt (4 )); /// // indexOf ('e', startIndex) method: obtain the position where the specified string appears for the first time. StartIndex indicates the number of times to start searching. Var s2 = 'after knowing it, I think it has passed another autumn'; alert (s2.indexOf ('ta', 3); // 6 // split ('delimiter ', returns a string as an array based on the delimiter. // Limit indicates the maximum length of the array to be returned (customizable ). Var s3 = 'horse | in the rivers and lakes | kill '; alert (s3.split (' | ', 2); // use | as the separator to split the string and display it as an array, and only contains two elements var arr = s3.split ('|', 3); // three elements for (var I = 0; II hope this article will help you design javascript programs.