1. 程式人生 > >過濾陣列中重複的資料

過濾陣列中重複的資料

var arr = [
			{name: 'sxy',type: '1'},
			{name: 'sxy',type: '2'},
			{name: 'sxy',type: '2'},
		]
		var addArr = [
			{name: 'sxy',type: '1'},
			{name: 'hhh',type: '2'},
		]
		var newArr = [];
		for (var i in addArr) {
			var count = 0;
			for(var j in arr) {
				if(addArr[i].name == arr[j].name && addArr[i].type == arr[i].type) {
					count++
					break
				}
			}
			if(count === 0) {
				newArr.push(addArr[i])
			}
		}
		console.log(newArr)