1
我試圖使用下劃線獨特的功能,但無法得到它的工作,這是我的測試代碼:underscorejs獨特不起作用
var foo = [ { "a" : "1" }, { "b" : "2" }, { "a" : "1" } ];
_.unique(foo, function(item, k, v){
return item.a;
});
console.log(foo);
_.unique(foo, 'a');
console.log(foo);
如這裏refered:Removing duplicate objects with Underscore for Javascript和測試代碼這裏:http://jsfiddle.net/bingjie2680/wDvpM/2/,都打印出三個對象。我無法弄清楚問題,有人可以幫忙嗎?非常感謝。
感謝,但我仍然得到輸出三個對象。 – bingjie2680
對不起,我的回答的代碼是正確的,但我鏈接到錯誤的小提琴。我修正了這一點。 –
好吧,它的工作原理。非常感謝。 – bingjie2680