ES6 数组去重并且统计数量

				function alltotal(data) {
					if (data.length > 0) {
						let temp = {};
						//reduce函数很好用具体用法可以查一查
						let data1 = data.reduce((cur, next) => {
							temp[next.ID] ? "" : temp[next.ID] = true && cur.push(next);
							return cur;
						}, [])
						return data1.length;
					} else {
						return 0;
					}
				}
				let list = [
						{ ID: 1, Name: "王1" },
						{ ID: 2, Name: "王2" },
						{ ID: 3, Name: "王3" },
						{ ID: 4, Name: "王4" },
						{ ID: 5, Name: "王5" },
						{ ID: 1, Name: "王1" },
						{ ID: 2, Name: "王2" },
						{ ID: 3, Name: "王3" },
						{ ID: 4, Name: "王4" },
						{ ID: 5, Name: "王5" },
						{ ID: 1, Name: "王1" },
						{ ID: 1, Name: "王1" },
				]
				let total = alltotal(list)
				

你可能感兴趣的:(vue,es6,JavaScript,javascript,vue.js,es,es6)