Created
December 11, 2014 06:33
-
-
Save jakeauyeung/7040c5a7797c4362d2c5 to your computer and use it in GitHub Desktop.
数组去重
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _user = [ | |
{'id': '11', 'name': 'fame'}, | |
{'id': '11'}, | |
{'id': '22'} | |
], | |
newArr = [] | |
for(var i = 0,len = _user.length; i < len; i++){ | |
for(var j = i + 1; j < len; j++){ | |
if(_user[i]['id'] == _user[j]['id']){ | |
j = ++i | |
} | |
} | |
newArr.push(_user[i]) | |
} | |
console.log(newArr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment