How to remove duplicates from front-end html array

不言
Release: 2018-07-09 17:36:19
Original
3330 people have browsed it

This article mainly introduces the method of deduplicating front-end html arrays. It has certain reference value. Now I share it with you. Friends in need can refer to it

Array deduplication

Knowledge points used:

1:indexOf()

This method returns the index value of the firstoccurrence of elementin the array;

If there is, the index value will be returned normally;

If the retrieved content does not exist in the array , then return -1

2: for loop

Exercise: Array deduplication

//The first method

##

var aList = [1,2,3,4,4,3,2,1,2,3,4,5,6,5,5,3,3,4,2,1]; var aList2 = []; for (var i = 0 ; i < aList.length ; i ++) {   var value = aList[i]   if (aList.indexOf(value) + 1) {     console.log('重复了',value)   } else {     aList2.push(value)   }           }   console.log(aList2)
Copy after login
// 第二种方法 var aList = [1,2,3,4,4,3,2,1,2,3,4,5,6,5,5,3,3,4,2,1]; for(var i=0;i
        
Copy after login
// 第三种方法 var aList = [1,2,3,4,4,3,2,1,2,3,4,5,6,5,5,3,3,4,2,1]; for (var i = 0; i < aList.length; i++) {   var item = aList[i] if (newArray.indexOf(item) == -1) {   newArray.push(item) } else {   console.log('重复了',item) } }
Copy after login

Above That’s the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

htmlMaking login form

Basic elements of html form

The above is the detailed content of How to remove duplicates from front-end html array. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!