0
我想,我有三個數組:JavaScript的關聯數組比較
dict['tag'] = 'INPUT';
dict['type'] = 'checkbox';
dict['name'] = 'remember'
dict2['tag'] = 'INPUT2';
dict2['type'] = 'checkbox';
dict2['name'] = 'remember';
dict3['type'] = 'checkboxEdit';
dict3['name'] = 'remember'
dict3['tag'] = 'INPUT3';
現在我要實現的是,我想知道數組的元素有多少是平等的,即使數組進行排序,因此例如
function(dict, dict2) return 2 //cause input values are not the same
function(dict, dict3) return 1 //cause name values are the same
function(dict2, dict3) return 1 //cause name values are the same
什麼是最有效的方法來實現這一目標?另外數據結構可以改變,所以如果有更好的東西,讓我知道。
JavaScript沒有 「關聯數組」。它有*對象*。 (這將有助於您的搜索。) –
*「也可以更改數據結構,所以如果有更好的東西,請告訴我。」*您可能會更好地使用一組對象,例如。 '[tag:'INPUT',type:'checkbox',name:'remember'},{'tag:'INPUT2','type':'checkbox',name:'remember'},...] (什麼是「INPUT2」?) –
Input2不是有效的標籤,對此爲sry :),但讓我們假設它是div :) –