我對在JavaScript中迭代到JS對象和一些數組函數有些懷疑。比方說,我有這些變量:映射到另一個節點並比較節點
var json1 = "[{"id": 1, "name":"x"}, {"id": 2, "name":"y"}]";
var json2 = "[{"id": 1, "name":"x"}, {"id": 2, "name":"y"}, {"id": 3, "name":"z"}]";
我如何能陣列
var ids1 = json1.ids (would be 1,2)
var ids2 = json2.ids (would be 1,2,3)
在做一個變量,只有ID和使另一個變量只與不同的ID
var idsdiff = diff(ids1, ids2) (would be 3)
您的JavaScript對象不正確。你有嵌套的引號 - 還要注意[JSON不是JavaScript對象](012)http://www.fizerkhan.com/blog/posts/JSON-is-not-Javascript-Object.html) – mplungjan