[英]lodash Library k- only extract keys
I need a little help.我需要一点帮助。 I need to get an object from the console log and return only his keys using the lodash library, i tried
我需要从控制台日志中获取一个对象并使用 lodash 库只返回他的密钥,我试过了
const ObjLetters = ({value}) => {
return _.findKey({value}) }
console.log (ObjLetters{
miki:"handsome",
shon:"adorable"
tomer:"man"})
im not aware of my problem, if its a syntax problem or maybe the wrong commands.我不知道我的问题,如果它是语法问题或者可能是错误的命令。
Are you trying to obtain an array of keys in an object ?您是否正在尝试获取对象中的键数组?
If yes, try如果是,请尝试
console.log(Object.keys({
miki: "handsome",
shon: "adorable"
tomer: "man",
}));
// output: ["miki", "shon", "tomer"]
Ok, now my code looks like this:好的,现在我的代码如下所示:
const ObjLetters = ({object}) => {
return _.keys({object}) }
console.log (ObjLetters({ miki:"handsome", shon:"adorable", tomer:"man"}))
but, instead of returning the keys, i get但是,我没有归还钥匙,而是得到
'object'
if you just want the keys you can use:如果您只想要可以使用的密钥:
const ObjLetters = (object) => _.keys(object)
console.log(ObjLetters({ miki:"handsome", shon:"adorable", tomer:"man"}))
// out: ["miki", "shon", "tomer"]
_ findKey find a key of the object with the values passed. _ findKey 找到传递值的对象的键。
see this example from docs:从文档中查看此示例:
var users = {
'barney': { 'age': 36, 'active': true },
'fred': { 'age': 40, 'active': false },
'pebbles': { 'age': 1, 'active': true }
};
_.findKey(users, { 'age': 1, 'active': true });
// out: 'pebbles'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.