我有这样的对象数组-
[{"name":"admission[year]","value":"2011-12"},{"name":"admission[class]","value":"Nursery"}]
我如何使用javascript访问名称值对,例如入学[year]-2011-12和入学[class]-托儿所。
最佳答案
var x = [{"name":"admission[year]","value":"2011-12"},{"name":"admission[class]","value":"Nursery"}]
var i, len = x.length;
for(i = 0; i < len; i++)
console.log(x[i].name + ': ' + x[i].value);
输出:
admission[year]: 2011-12
admission[class]: Nursery
IE浏览器
x[0].name === "admission[year]"
和x[1].value === "Nursery"