获取带有索引的 JS 对象元素 [英] Get element of JS object with an index

查看:57
本文介绍了获取带有索引的 JS 对象元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,假设我有我的对象

Ok so let's say that I have my object

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

我想从中取出第一个元素.就像我希望它返回 Abe 一样,它的索引为 A.我怎样才能按照 myobj[0] 的思路做一些事情并摆脱Abe".

and I want to get the first element out of it. As in I want it to return Abe which has an index of A. How can I do something along the lines of myobj[0] and get out "Abe".

推荐答案

我知道这是一个迟到的答案,但我认为这是 OP 要求的.

I know it's a late answer, but I think this is what OP asked for.

myobj[Object.keys(myobj)[0]];

这篇关于获取带有索引的 JS 对象元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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