////// 数组去重/// /// 去重的字段名 Array.prototype.distinct = function (fieldName) { var arr = this; var uniqueArr = []; var includedKey = {}; for (var i = 0; i < arr.length; i++) { var value = arr[i][fieldName]; if (includedKey[value]) continue; uniqueArr.push(arr[i]); includedKey[value] = 1; } return uniqueArr;}// 测试var test = [{ id: '1' }, { id: '2' }, { id: '2' }, { id: '1' }, { id: '3' }];test = test.distinct('id');alert(JSON.stringify(test));