匹配值我有一個數組是這樣的:獲取和陣列
var Data=[{
"Class":"item1","element":["a","b","c","d","e"],
"Class":"item2","element":["a","b","c","d","e"],
"Class":"item3","element":["a","b","c","d","e"],
"Class":"item4","element":["a","b","c","d","e"]
}];
我有兩個變量:
var class='item1';
var element='a';
我希望有一個條件,如果VAR類值匹配「物品1」那麼var元素的值應該與它的元素匹配,如:
if(class == Data.Class)then元素應該與它附近的Data.element匹配
有何想法?所有你需要修復的
您的'數據'變量是錯誤的。你怎麼能有相同的鍵/值對4次。只有最後一個將被存儲。 – mohkhan
「Data」數組中的對象重新定義了「Class」和「element」。你是否意味着每一行都是數組中的獨立對象? – freejosh
yes freejosh和什麼應該是它的最佳結構mohkhan – Hushme