var data=[{name:"a",age:12},{name:"b",age:11},{name:"c",age:13},{name:"d",age:14}]
for(var o in data){
alert(o)
alert(data[o])
alert("text:"+data[o].name+" value:"+data[o].age )
}
或是
<script type="text/javascript">
function text(){
var json = {"options":"[{/"text/":/"王家湾/",/"value/":/"9/"},{/"text/":/"李家湾/",/"value/":/"10/"},{/"text/":/"邵家湾/",/"value/":/"13/"}]"}
json = eval(json.options)
for(var i=0i<json.lengthi++)
{
alert(json[i].text+" " + json[i].value)
}
}
</script>
思路
1、获取key值cxxx和对应的value值
2、去掉c,获取数值
3、根据key获取到的数值把对应的value值放入数组中(把字符串转换为整数,parseInt(value,进制))
var str = {"c4":564,"c6":14,"c7":1,"c1":573}var localStorage=[]
for(var key in str){
localStorage[parseInt(key.replace('c',''),10)]=parseInt(str[key],10)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)