在以下字符串中,如何访问元素For ex:
var s= "{4:123,5:456}"
for(var i=0;i<s.split(",").length;i++)
{
console.log(s[i][0]) // should give me 4,5
console.log(s[i][1]) // should give me 123,456
}
答案 0 :(得分:0)
我认为代码应该是:
var s= {4:123,5:456}
for(var entry in s)
{
console.log(entry); // should give me 4,5
console.log(s[entry]); // should give me 123,456
}