当前位置:网站首页>Important methods of array and string

Important methods of array and string

2022-07-06 12:07:00 KAMHUNCHAN

ArrayString
indexOf( Array elements , Specify where to start searching ) // Returns the first index number that satisfies the condition , If you can't find it, go back to -1str.indexOf(“ Search for characters ”, Start looking for the location ) // Return the first found subscript , Return if not found -1
lastIIndexOf( Array elements ) // Returns the last index number that meets the condition , If you can't find it, go back to -1
Convert to string arr.toString() ;arr.join("-") Convert to array :str.split(’=’)
slice(begin,end) // Intercept array intercept array subscript from begin To end The content of , It doesn't contain endbegin Out of array range , Will return an empty array slice(begin,end);substring(begin,end) Negative values are not acceptable , these two items. end It's a subscript , Can't get ;substr(star,length)length It's a number
splice(star,deleteCount,item1, item2, … Optional )-start​ Specify where to start the modification ( from 0 Count ). If the length of the array is exceeded , Then add content from the end of the array ; If it's negative , Represents the number of bits starting from the end of the array ( from -1 Count , It means -n It's the last n And is equivalent to array.length-n); If the absolute value of a negative number is greater than the length of the array , It means that the starting position is 0 position .deleteCount Optional integer , Represents the number of array elements to remove . If deleteCount Greater than start The total number of elements after , From start Later elements will be removed ( Hendy start position ). If deleteCount Was omitted , Or its value is greater than or equal to array.length - start( in other words , If it is greater than or equal to start The number of all elements after ), that start After that, all elements of the array will be deleted . If deleteCount yes 0 Or negative , The element is not removed . In this case , At least one new element should be added .item1, item2, … Optional elements to be added to the array , from start Position start . If you don't specify , be splice() Only array elements will be removed . The return value is an array of deleted elements . If only one element is deleted , Returns an array containing only one element . If the element is not deleted , Then return an empty array . This method will change the original array -
原网站

版权声明
本文为[KAMHUNCHAN]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131605109526.html