This article describes the common methods of String in Javascript. Share it for your reference. The details are as follows:
// length attribute: gets the number of characters in the string. var s='Love is like a gust of wind'; alert(); // charAt(index) method: get the character at the specified index position, the index starts from 0 var s1='I don't want to miss you anymore'; alert((4));//think// indexOf('e',startIndex) method: Get the location where the specified string first appears. startIndex means the search starts from the first one. var s2='I realized that it was another autumn afterwards'; alert(('Pass',3));//6 // split('delimit',limit); returns a string to an array according to the delimiter.//limit indicates the maximum length of the array to be returned (customizable). var s3='Quick Horse|In the World|Fight'; alert(('|',2)); //Segmented with |, split the string, display it as an array, and contains only two elements var arr=('|',3);//Three elements for(var i=0;i<;i++){ alert(arr[i]); } // substr(startIndex,len) starts from startIndex (including), and then intercepts len characters. var s4='A black sweater'; alert((4,2));// Sweater, starting from subscript 4, including 4, and two characters are intercepted later// substring(startIndex, stopIndex) starts with startIndex,// Intercept the stopIndex position (excluding the characters where stopIndex is located) var s5='Fireworks are easy to get cold and people are easy to separate'; alert((1,4));//Flowers are easy to cool, starting from 1 to 4, excluding 1 and 4// toUpperCase() converts uppercase, toLowerCase(); converts lowercase var s6='What are you kidding me'; alert(()); alert(());
I hope this article will be helpful to everyone's JavaScript programming.