如何在对象内选择第n个项目 [英] How to select nth item inside the object

查看:82
本文介绍了如何在对象内选择第n个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说如果您无法通过像objectName.objectItem这样的点表示法访问对象中的某个项目,即它在时间上具有随机名称.有没有办法像第二项一样替代性地访问它?

Say if you were unable to access a certain item inside an object through dot notation like objectName.objectItem i.e. it has random name al the time. Is there a way to alternatively access it like second item?

如何仅通过知道第二个物品从那里获得这个物品的物品?:

how to get item2 from this object by only knowing that it is second item there?:

something: {
  item1: "text",
  item2: "text",
  item3: "text:,
  ...
}

推荐答案

javascript对象中的键顺序不固定.

Order of keys are not fixed in javascript object.

您可以尝试

var secondKey = Object.keys(something)[1]; //fetched the key at second index
alert(something[secondKey ]);

这篇关于如何在对象内选择第n个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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