Posted in Javascript onMay 30, 2018
本文实例讲述了JS实现键值对遍历json数组功能。分享给大家供大家参考,具体如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>3water.com js键值对遍历json数组</title> </head> <body> <script type="text/javascript"> var data = []; var data = []; data['上海'] = [{ city:'闵行', value:'minhang' },{ city:'浦东', value:'pudong' }]; data['四川'] = [{ city:'温江', value:'wenjiang' },{ city:'成都', value:'chengdu' }]; // 遍历数组 for(var province in data){ for(var i=0;i<data[province].length;i++){ console.log(province + ' - ' + data[province][i].city + ' - ' + data[province][i].value); } } </script> </body> </html>
运行结果如下:
JS实现键值对遍历json数组功能示例
- Author -
库塔姆斯声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@