Slice function usage instance analysis in javaScript and slice instance analysis

Source: Internet
Author: User

Slice function usage instance analysis in javaScript and slice instance analysis

This article describes the slice function usage in javaScript. Share it with you for your reference. The specific analysis is as follows:

The slice function in javaScript returns an array segment for the slice function of the array object. (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.

Note:

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's 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 = testurlvar 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.yoursiteweb.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>

I hope this article will help you design javascript programs.

Related Article

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.