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!