如何使用javascript访问密钥本身 [英] How to access key itself using javascript

查看:52
本文介绍了如何使用javascript访问密钥本身的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似的JSON:

I have a JSON like:

  var xx = {'name':'alx','age':12};

现在我可以将名称'alx'的值读作xx [0] .name,但是我应该如何检索'name'本身的值?这样,我的意思是如何在运行时获取密钥?

Now I can read the value of name which is 'alx' as xx[0].name, but how should I retrieve value of 'name' itself? By that, I mean how can I fetch the key at run time?

推荐答案

for (i in xx) {
    if (xx[i] == "alx") {
        // i is the key
    }
}

这篇关于如何使用javascript访问密钥本身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆