天天看点

JavaScript中遍历获取Json中属性值

JavaScript中遍历获取Json中属性值

JavaScript中遍历获取Json中属性值
JavaScript中遍历获取Json中属性值

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <script type="text/javascript">
    var data = { name: '小花', age: '17岁', sex: '男' };
    for (var a in data) {
        console.log('这是属性名' + a); /*属性名*/
        console.log('属性值' + data[a]); /*属性值*/
    };
    </script>
</body>

</html>      

属性名~属性值

JavaScript中遍历获取Json中属性值
JavaScript中遍历获取Json中属性值
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <script type="text/javascript">
    var a = ['橡胶', '苹果', '土豆'];
    for (var x in a) {
        console.log('在数组中的位置 - '+x); /*在数组中的位置*/
        console.log('值 - '+a[x]); /*值*/
    };
    </script>
</body>

</html>      

下标值~属性值

本文来自博客园,作者:農碼一生,转载请注明原文链接:https://www.cnblogs.com/wml-it/p/15079934.html

技术的发展日新月异,随着时间推移,无法保证本博客所有内容的正确性。如有误导,请大家见谅,欢迎评论区指正! 个人开源代码链接: GitHub:

https://github.com/ITMingliang

Gitee:

https://gitee.com/mingliang_it

GitLab:

https://gitlab.com/ITMingliang

进开发学习交流群:
JavaScript中遍历获取Json中属性值
c#