📜  Lodash _.values() 方法

📅  最后修改于: 2022-05-13 01:56:46.915000             🧑  作者: Mango

Lodash _.values() 方法

_.values()方法用于返回对象自己的可枚举字符串键控属性值的数组。

句法:

_.values(object)

参数:此方法接受如上所述和如下所述的单个参数:

  • object:此参数保存要查询的对象。

返回值:此方法返回对象元素的属性值数组。

示例 1:

Javascript
// Requiring the lodash library  
const _ = require("lodash");  
  
// The source object
var obj = { 
    Name: "GeeksforGeeks", 
    password: "gfg@1234", 
    username: "your_geeks"
}
  
// Use of _.values() method 
console.log(_.values(obj));


Javascript
// Requiring the lodash library  
const _ = require("lodash");  
  
// The source function
function Fb() {
  this.id = 2045;
  this.username = 'fb_myself';
  this.password = 'fb1234';
}
    
// This will not get included in values array
Fb.prototype.email = 'myself@gmail.com';
  
// Use of _.values() method 
console.log(_.values(new Fb)); 
console.log(_.values('GFG'));


输出:

["GeeksforGeeks", "gfg@1234", "your_geeks"]

示例 2:

Javascript

// Requiring the lodash library  
const _ = require("lodash");  
  
// The source function
function Fb() {
  this.id = 2045;
  this.username = 'fb_myself';
  this.password = 'fb1234';
}
    
// This will not get included in values array
Fb.prototype.email = 'myself@gmail.com';
  
// Use of _.values() method 
console.log(_.values(new Fb)); 
console.log(_.values('GFG'));

输出:

[2045, "fb_myself", "fb1234"]
['G', 'F', 'G']