1. stringObject.charAt()
Function: Return the subscript of the string
var str="This is a string";console.log(str.charAt(0))//This
2. stringObject.charCodeAt()
Function: The method can return the Unicode encoding of the characters at the specified position
var str="This is a string";console.log(str.charCodeAt(0))//This =>36825
3.String.fromCharCode()
Function: Return the corresponding characters through Unicode encoding
console.log(String.fromCharCode(36825,26159))//This is
Example: Find if a string is a number
<body><input type="text" /><input type="button" value="detection" /><script>var aInp = document.getElementsByTagName('input');aInp[1].onclick = function () { var val = aInp[0].value; if ( detectNum(val) ) { alert( 'Congratulations, '+ val +' are all numbers' ); } else { alert('Input is wrong'); }};function detectNum ( str ) { var n = 0; for ( var i=0; i<str.length; i++ ) { n = str.charCodeAt(i); if ( n<48 || n>57 )return false; } return true;}</script></body>4. stringObject.indexOf()
Function: The method can return the location where a specified string value first appears in the string.
Parameters: str.indexOf (find the value, start looking for the subscript). If the string value to be retrieved does not appear, the method returns -1.
Example: Return to find the subscript of the corresponding character
<script> var str = 'xsxsxscdecdcdxsxsxs'; var num = 0; var s = 'xs'; var arr = []; for (; str.indexOf(s, num) != -1;) { num = str.indexOf(s, num) + s.length arr.push(num) } console.log(arr) </script>5. stringObject.lastIndexOf()
Function: Find the first location of a specified string value in the string from behind to front.
6. stringObject.substring()
Function: The method is used to extract characters in a string that are between two specified subscripts.
7. stringObject.toUpperCase()
Function: Convert letters to capital
8. stringObject.toLowerCase()
Function: Convert letters to lowercase
9.stringObject.split()
Function: Method is used to split a string into a string array
Parameters: (What character is used to intercept and which bit the array is retained)
Three usages
var str="121314";str.split("") //[1,2,1,3,1,4];str.split("1")//[ ,2,3,4];str.split("",2)//[1,2]10.arrObject.join()Function: The method is used to put all elements in the array into a string. Elements are separated by specified delimiters
Two usages
var arr = [1,2,3];arr.join("")//123arr.join("-")//1-2-3Example: Highlight the keywords you searched
<input type="text" id="oin" /> <button>button</button> var oin = document.getElementById("oin"); var obtn = document.getElementsByTagName('button')[0]; var str = "The length of the arguments object is determined by the number of real parameters rather than the number of formal parameters. The formal parameters are variables that reopen memory spaces within the function, but they do not overlap with the memory space of the arguments object. In the case where both arguments and values exist, the values are synchronized, but for one of them, the values are not synchronized for this valueless situation. The following code can be verified."; var h = ""; obtn.onclick = function() { if (oin.value == "") { alert("Input is empty"); return false } var s = oin.value; if (str.indexOf(s) == -1) { alert("No this number"); return false } var m = '<span style="background-color:red">' + s + '</span>'; str = str.split(s); h = str.join(m) document.body.innerHTML=h }