我想在一个对象中获取数组大小的帮助:
var st = { "itema":{...},"itemb":[{"id":"s01","cd":"c01","dd":"d01",....}{"id":"s02","cd":"c02","dd":"d02",....}]}
如何计算"itemb"
内的对象(在本例中为2)?
答案 0 :(得分:85)
Javascript数组具有length属性。像这样使用它:
st.itemb.length
答案 1 :(得分:19)
数组有一个属性.length
,它返回元素的数量。
var st =
{
"itema":{},
"itemb":
[
{"id":"s01","cd":"c01","dd":"d01"},
{"id":"s02","cd":"c02","dd":"d02"}
]
};
st.itemb.length // 2