Get element of JS object with an index

后端 未结 7 1165
南方客
南方客 2021-01-30 20:43

Ok so let\'s say that I have my object

myobj = {\"A\":[\"Abe\"], \"B\":[\"Bob\"]}

and I want to get the first element out of it. As in I want i

相关标签:
7条回答
  • 2021-01-30 21:29
    var myobj = {"A":["Abe"], "B":["Bob"]};
    
    var keysArray = Object.keys(myobj);
    
    var valuesArray = Object.keys(myobj).map(function(k) {
    
       return String(myobj[k]);
    
    });
    
    var mydata = valuesArray[keysArray.indexOf("A")]; // Abe
    
    0 讨论(0)
提交回复
热议问题