js-emptying array arrays

Source: Internet
Author: User

1. Splice:Deletes the element and adds a new element, modifying the array directly, returning the arrays containing the deleted elements.
      Arrayobject.splice (index,howmany,element1,....., elementx)
Index: Required,specifies where to add/remove elements from. Howmany: Must be selected,specifies how many elements should be deleted. If this parameter is not specified, all elements from index start to the end of the original array are deleted . Element1: Optional, specifies the new element to be added to the array. JS Code
    1. <script type ="Text/javascript">
    2. var arr = [1,2,3,4];
    3. Arr.splice (0,arr.length);
    4. document.write (arr); //
    5. </script>

2.length Properties: Sets or returns the number of elements in the array.

      Arrayobject.length
length= element The last subscript +1,length value of 0 empties the elements within the array (excluding array elements that do not include an integer).The length value set is smaller than the value of the current array, the array is truncated, and the trailing element is lost. Set the lengthThe value is larger than the value of the current array, the array is incremented, the new element is added to the end of the array, and the value is undefined. JS Code
    1. <script type ="Text/javascript">
    2. var arr = [1,2,3,4];
    3. arr.length=0;
    4. document.write (arr); //
    5. </script>
Http://www.w3school.com.cn/js/jsref_splice.asp

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.