Lodash _.keysIn() 方法
_.keysIn()方法用于创建对象自己的和继承的可枚举属性名称的数组。
句法:
_.keysIn(object)
参数:此方法接受如上所述和如下所述的单个参数:
- object:此参数保存要查询的对象元素。
返回值:此方法返回给定对象的所有键的数组。
示例 1:
Javascript
/// Requiring the lodash library
const _ = require("lodash");
function Gfg() {
this.a = 1;
this.b = 2;
}
Gfg.prototype.c = 3;
// Use of _.keysIn method
console.log(_.keysIn(new Gfg));
Javascript
/// Requiring the lodash library
const _ = require("lodash");
// Given object
var obj = {
Name: "GeeksforGeeks",
password: "gfg@1234",
username: "your_geeks"
}
// Use of _.keysIn method
console.log(_.keysIn(obj));
输出:
['a', 'b', 'c']
示例 2:
Javascript
/// Requiring the lodash library
const _ = require("lodash");
// Given object
var obj = {
Name: "GeeksforGeeks",
password: "gfg@1234",
username: "your_geeks"
}
// Use of _.keysIn method
console.log(_.keysIn(obj));
输出:
["Name", "password", "username"]