how to access immediate unknown key in object

前端 未结 2 492
走了就别回头了
走了就别回头了 2020-12-20 23:34

how to access immediate unknown key in object. in pic \"367:sl\" is dynamic key and i want to access cptyName value which is in \"367:sl\". Thanks in advance

相关标签:
2条回答
  • 2020-12-20 23:49

    You can iterate through the object.

    var quotes = {
        '367:sl': 'cptyname'
    }
    
    for(var i in quotes) {
        alert(quotes[i]);
    }
    

    Demo

    0 讨论(0)
  • 2020-12-21 00:01

    If your dynamic key is the only key in quotes object, you can get the first key and then access value with:

    var firstKey = Object.keys(quotes)[0];
    var cptyName = quotes[firstKey].cptyName;
    

    http://jsfiddle.net/mGZpa/

    0 讨论(0)
提交回复
热议问题