無法通過數組獲得以下方法。我打算將數組減少爲唯一值,但是,獲得每個獨特元素的總數。例如,獲得了最終的陣列,如:帶計數的唯一關聯數組
var data = [14:"A",5:"IMG",2:"SPAN"]
這對應於每一個獨特的標籤總的項目,與標籤本身相關聯。 我原來的樣品陣列如下:
var data = ["A", "A","A","IMG","IMG","A","A","IMG","A","A","IMG","A","A","IMG","IMG","A","A","A","A","A","SPAN","SPAN"]
您可以對原始數組(或其深層副本)進行排序,然後對雙打進行計數。順便說一句。在你的例子中有14個「A」和6個「IMG」... – Teemu
http://mattgemmell.com/2008/12/08/what-have-you-tried/ – pckill
謝謝。但問題的確在於,使用與標籤相關的計數來構建新的關聯數組。 – McRui