JS indexof split Join function usage articles for you to provide a free JS indexof split Join function usage, focusing on the indexof and split function of the detailed usage and examples of the explanation oh.
Join
var delimitedstring=myarray.join (delimiter);
var mylist=new array ("JPG", "BMP", "GIF", "ico", "PNG");
var portablelist=mylist.join ("|");
The result is Jpg|bmp|gif|ico|png
.
IndexOf () Definition and usage
The indexof () method returns the location of the first occurrence of a specified string value in a string.
Grammar
Stringobject.indexof (searchvalue,fromindex) parameter description
Searchvalue required. A string value that requires retrieval.
Fromindex an optional integer parameter. Specify where to start retrieving in the string. Its legal value is 0 to stringobject.length-1. If this argument is omitted, it is retrieved from the first character of the string.
indexof
var mystring= "web Effects";
var w=mystring.indexof ("V"); W'll be 2
var x=mystring.indexof ("S"); X would be 4
var y=mystring.indexof ("script"); y'll also be 4
var z=mystring.indexof ("key"); Z'll be-1
Look at a indexof instance
<script type= "Text/javascript" >
var str= "Hello world!"
document.write (Str.indexof ("hello") + "<br/>")
document.write (Str.indexof ("World") + "<br/>")
document.write (Str.indexof ("World"))
</script> the output of the above code:
0
-1
6
Split
Definitions and usage
The split () method is used to split a string into an array of strings.
Grammar
Stringobject.split (separator,howmany) parameter description
Separator required. A string or regular expression that splits the Stringobject from the place specified by the parameter.
Howmany Optional. This parameter specifies the maximum length of the array to return. If this argument is set, the returned substring will not be more than the array specified by this parameter. If this argument is not set, the entire string is split, regardless of its length
str= "Jpg|bmp|gif|ico|png";
Arr=thestring.split ("|");
Arr is an array that contains the character values "JPG", "BMP", "GIF", "ico", and "PNG"
Look at an example
<script type= "Text/javascript"
var str= "How are your doing today?"
document.write (Str.split ("") + "<br/>")
document.write (Str.split ("") + "<br/>")
document.write (Str.split ("", 3))
</script>