Example of a simple method for JS to implement array deduplication

Source: Internet
Author: User
This article mainly introduces the method of simple array deduplication in JS, involving the traversal, judgment, and value assignment operations of javascript arrays. The code is very simple and easy to understand and has reference value, for more information about how to use javascript to deduplicate arrays, see the next article. This article describes how to use javascript to retrieve, judge, and assign values to javascript arrays. The code is very easy to understand, it has some reference value. For more information, see

The example in this article describes how to implement array deduplication in JS. We will share this with you for your reference. The details are as follows:

JS array deduplication

 Script var arr = [678, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8, 8]; var result = []; for (var I = 0; I <arr. length; I ++) {if (result [arr [I]) {} else {result [arr [I] = arr [I] ;}} console. log (result); script

Run the following command:

The problem occurs. The value of the new array corresponds to the index value. Limitations. Although it can be arranged in ascending order.

The above is the details of the simple method example for JS to implement array deduplication. For more information, see other related articles in the first PHP community!

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.