我有2個JS數組,我遍歷他們兩個找到相似的。JavaScript對象沒有得到正確的成員值
anomalies.forEach(function(anomaly) {
links.forEach(function(link) {
if ((link.source.name === anomaly.source) && (link.target.name === anomaly.target)) {
console.log("anomaly");
link.type = "anomaly";
console.log(link);
} else {
link.type = "normal";
}
});
});
console.log(links);
在的link.type
值應"anomaly"
的情況下,其仍體現爲"normal"
。
爲什麼是這樣,應該做什麼?
無法重現 - > http://jsfiddle.net/z39d8z1z/ – adeneo
數組內容是什麼樣的?沒有看到,很難說你的代碼是否正確。 – Pointy