I have an array of numbers that I need to make sure are unique. 我须要肯定一个惟一的数字数组。 I found the code snippet below on the internet and it works great until the array has a zero in it. 我在互联网上找到了下面的代码片断,而且在数组中包含零以前,它均可以正常工做。 I found this other script here on SO that looks almost exactly like it, but it doesn't fail. 我在SO上找到了另外一个脚本 ,看起来几乎彻底同样,可是它不会失败。 数组
So for the sake of helping me learn, can someone help me determine where the prototype script is going wrong? 所以,为了帮助我学习,有人能够帮助我肯定原型脚本出了什么问题吗? 学习
Array.prototype.getUnique = function() { var o = {}, a = [], i, e; for (i = 0; e = this[i]; i++) {o[e] = 1}; for (e in o) {a.push (e)}; return a; }