An array of simple chestnuts to go heavy

Source: Internet
Author: User

There are many ways to get an array of methods, and here are some examples of ways that you think are easier to understand.

Ideas:

    1. Create a new empty array to hold the new array after the redo.
    2. Use the For Loop loop to iterate through the array that needs to be weighed.
    3. Use the indexOf() method to query whether the traversed array appears in the new array, and if it does: continue to iterate through the array, if it does not appear: Use the push method to add to the new array.
    4. After the original array loop traversal is complete, a new array is formed that has been removed.
<Script>    var arr = [1,3,4,5,6,7, 4,3,2,4, 5,6,7, 3,2]; function removerepeatarr (var newArr = []; for (var i = 0; i < arr.length; i++ {if (Newarr.indexof (arr[i]) = = -1) {Newarr.push (arr[i]);}} document.write (NEWARR); } 
 Removerepeatarr     </script>         

indexOf:

return value:

    • Returns 1 if the retrieved result has no matching value.
    • Returns 1 if the retrieved result matches to.
    • The return value is negative positive 0, which is no longer explained in detail, and an explanation is also opened.

An array of simple chestnuts to go heavy

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.