JS indexOf split Join function usage

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.