【发布时间】:2017-07-10 10:27:41
【问题描述】:
我需要获取具有值的对象的最后一个键。所以如果这将是对象...
const obj = { first: 'value', second: 'something', third: undefined, fourth: undefined }
...我需要得到second
obj = { first: 'value', second: 'something', third: 'else', fourth: undefined }
// result should be: 'third'
obj = { any: 'value', other: 'something', thing: undefined, bla: undefined }
// result should be: 'other'
【问题讨论】:
-
你如何定义“last”,那些是对象的字段。
-
@user3142695 你的意思是你的问题只针对这个特定的对象吗?
-
"last" 对对象属性没有意义。订单不相关
-
对象的属性没有内在的顺序,所以你的问题实际上没有意义。没有“最后一个”键。浏览器通常按字母顺序列出属性,例如在开发者控制台中,但这只是为了方便开发者。数组是具有内在顺序的结构。
-
我投票决定将此问题作为离题结束,因为没有更多信息,无法解决。
标签: javascript