A few days ago to do projects, using these functions, here to summarize, deepen learning comprehension:
1. Split() function to split a string into a string array
Usage:stringobject.split (separator,howmany);
The first parameter, which is required, is a string or regular expression that represents the partition of the Stringobject from the location specified by the parameter .
The second parameter, which is optional, returns the maximum length of the array.
Return value: An array of strings. The array is created by splitting the string stringobject into substrings at the boundary specified by separator .
Note : to split into a single character, use:str.split (""); see example below
Examples of Use:
<script type= "Text/javascript" >var str= "localstorage,is;good;localstorage;i;like;"; Var list=str.split (";") document.write (":
650) this.width=650; "Src=" http://s1.51cto.com/wyfs02/M02/7E/5F/wKioL1b9xBeCm4RdAACMjGtdwBo542.jpg " Title= "1.jpg" alt= "Wkiol1b9xbecm4rdaacmjgtdwbo542.jpg"/>2. Join (), set the array All the elements in a string , just the opposite of split .
Usage:arrayobject.join (separator);
has only one parameter and is optional. Specifies what delimiter to use to form a string.
Return value: Returns a string . The string is generated by Converting each element of Arrayobject to a string and then connecting the strings to insert a separator string between the two elements .
Note: If the . Join () has no arguments, a comma is used as the delimiter to compose the string.
Examples of Use:
<script> var str= "localstorage,is;good;localstorage;i;like ;"; var list=str.split (";"); document.write ("
:
650) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M01/7E/5F/wKioL1b9xKmxjL1xAABsImfiWPo197.jpg " Title= "2.jpg" alt= "Wkiol1b9xkmxjl1xaabsimfiwpo197.jpg"/>
3 . Splice () function : Adds or deletes an item to or from an array . Then returns the item that was deleted
Usage:arrayobject.splice (index,howmany,item1,....., ItemX)
The first parameter: must, indicates, add / Remove the position of the item, if a negativenumber.
Second argument: Required, indicates that you want to delete the number of items, and if set to 0, the item is not deleted .
A third parameter. Optional, represents a new item added to the array.
return value:arrayobject.splice (index,howmany,item1,....., ItemX) This value returns the deleted element, and now Arrayobject a new array that is re-composed after the element is deleted.
Note :1) If the second parameter is not written, then all elements from index start to the end of the original array will be deleted
2) When the parameter is negative, you can specify the position from the end of the array, starting with the number from the back, see the example below.
3) When you have a third argument, you are actually adding the item. See the example below for details
<script type= "Text/javascript" > var arr=new array (); Arr[0]= "Localstorage"; arr[1]= "is"; arr[2]= "good"; arr[3]= " I "; arr[4]=" like "; document.write (' :
650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M00/7E/5F/wKioL1b9xXfhfpsjAADgI0KV3mg028.jpg "title=" 3.jpg " alt= "Wkiol1b9xxfhfpsjaadgi0kv3mg028.jpg"/>
This article is from the "dream need to adhere to" blog, please be sure to keep this source http://xiyin001.blog.51cto.com/9831864/1759059
Split () function, join () function, splice () function study and summary