📜  Collect.js dump() 方法

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

Collect.js dump() 方法

collect.js 中的dump()方法用于打印特定时刻的数据,然后继续执行代码。

句法:

collect.dump()

参数:它不接受任何参数。

返回值:不返回任何值。

示例 1:

Javascript
// Importing the collect.js module
const collect = require('collect.js'); 
let array = ["a", "b", "c"];
  
// Making the collection
let collection= collect(array);
  
// Using dump() method to print
// the data at this moment
collection.dump()


Javascript
// Importing the collect.js module.
const collect = require('collect.js');
  
let array = ["a", "b", "c", "d", "e"];
  
// Making the collection
let collection = collect(array);
  
// Using dump() method to print
// the data at this moment
collection.dump()
    .filter((v, k) => v >= "c")
    .dump()


输出:

Collection { items: [ 'a', 'b', 'c' ] }

示例 2:

Javascript

// Importing the collect.js module.
const collect = require('collect.js');
  
let array = ["a", "b", "c", "d", "e"];
  
// Making the collection
let collection = collect(array);
  
// Using dump() method to print
// the data at this moment
collection.dump()
    .filter((v, k) => v >= "c")
    .dump()

输出:

Collection { items: [ 'a', 'b', 'c', 'd', 'e' ] }
Collection  { items: [ 'c', 'd', 'e' ] }

参考: https://collect.js.org/api/dump.html