获取JavaScript对象的第一个键名 [英] Get the first key name of a JavaScript object
本文介绍了获取JavaScript对象的第一个键名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我们具有以下JavaScript对象:
Let's assume we have the following JavaScript object:
ahash = {"one": [1,2,3], "two": [4,5,6]}
是否有一个函数返回给定对象的第一个键名?
Is there a function that returns the first key name for the given object?
在上面的示例中,由于该功能,我想获取one
.
From the example above I want to get one
as a result of that function.
推荐答案
在Javascript中,您可以执行以下操作:
In Javascript you can do the following:
Object.keys(ahash)[0];
这篇关于获取JavaScript对象的第一个键名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文