JS slice Functions

Source: Internet
Author: User

For the slice function of the array object,
Returns an array. (Still an array)
Arrayobj. Slice (START, [end])
Parameters
Arrayobj
Required. An array object.
Start
Required. The starting element of the part specified in arrayobj is the subscript calculated from scratch.
End
Optional. The ending element of the part specified in arrayobj is the subscript calculated from scratch.
Description
The Slice Method returns an array object, which contains the specified part of arrayobj.
The Slice Method is always copied to the end specified element, but this element is not included. If start is negative, it is processed as Length + start. Here, length is the length of the array. If end is negative, it is processed as Length + end. Here, length is the length of the array. If end is omitted, the slice method will always be copied to the end of arrayobj. If end appears before start, no elements are copied to the new array.
Example
In the following example, all elements in myarray are copied to newarray except the last element:
Newarray = myarray. Slice (0,-1)

 

-------- STR slice

<SCRIPT type = "text/JavaScript">

Function request (valuename, testurl)
{
VaR rtnval;
// Obtain the current webpage address. http: // 192.168.1.240: 85/test/asp/crmkorea_co_kr/test.htm? Para1 = atest
// Var nowaddress = Unescape (location. href );
VaR nowaddress = testurl
VaR parameters = new array ();
Alert (nowaddress. Slice (nowaddress. indexof ("? ") + 1, nowaddress. Length ))
Parameters = (nowaddress. Slice (nowaddress. indexof ("? ") + 1, nowaddress. Length). Split ("&");
For (VAR I = 0; I <parameters. length; I ++)
{Alert (I + "--" + parameters [I])
If (parameters [I]. indexof (valuename )! =-1)
{
Rtnval = parameters [I]. Split ("=") [1];
If (rtnval = undefined | rtnval = NULL)
{
Rtnval = "";
}
Return rtnval;
}
Else {
// Alert (parameters [0]. indexof (valuename ))
// Alert ("request must from:" + valuename)
}
}
Return ""
// Alert (rtnval );
}
VaR myaddr = "http://www.HCSTID.com /? Para1 = test1 & para1 = Test2"
Alert (Request ("para1", myaddr )) // Check whether the address contains the para1 parameter and return the value of this parameter.
</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.