Javascript Object.keys 等效的 lodash 方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35566472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 17:54:03  来源:igfitidea点击:

Object.keys equivalent lodash method

javascriptlodash

提问by user2936008

I am new to loadash, I am trying to learn good ways to manipulate java script object.

我是 loadash 的新手,我正在尝试学习操作 java 脚本对象的好方法。

Is there a equivalent loadash method for :

是否有等效的 loadash 方法:

Object.keys({ "tab1": "1" , tab2: "2"})[0];
Object.keys({ "tab1": "1" , tab2: "2"})[2];

to get list values?

获取列表值?

And also if there are easy and good ways to use lodash and any articles that I can go through.

并且如果有简单和好的方法来使用 lodash 和我可以阅读的任何文章。

回答by Alexander O'Mara

_.keysshould do the trick.

_.keys应该做的伎俩。

_.keys(object)

Creates an array of the own enumerable property names of object.

_.keys(object)

创建 的自己的可枚举属性名称的数组object

Example:

例子:

console.log(_.keys({ "tab1": "1" , tab2: "2"}));
console.log(Object.keys({ "tab1": "1" , tab2: "2"}));

// Outputs:
// ["tab1", "tab2"]
// ["tab1", "tab2"]
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.5.1/lodash.js"></script>

Side-note:

边注:

Remember that the keys of an object are not necessarily ordered, and so they can come back in any order the host chooses.

请记住,对象的键不一定是有序的,因此它们可以以主机选择的任何顺序返回。