pipe()方法用於保留回調函數並將此函數應用於集合中並返回相應的結果。
用法:
collect(array).pipe(callback)
參數:collect()方法采用一個參數,該參數將轉換為集合,然後將pipe()方法應用於該參數。 pipe()方法將回調保留為參數。
返回值:此方法返回應用於集合的回調函數的結果。
模塊安裝:使用以下命令從項目的根目錄安裝collect.js模塊:
npm install collect.js
以下示例說明了collect.js中的pipe()方法:
示例1:Filename:index.js
Javascript
// Requiring the module
const collect = require('collect.js');
// Creating collection object
const collection = collect([1,
2, 3, 5, 6, 8, 9, 11, 17, 22]);
// Function call
const pipe_val = collection.pipe(
element => element.max());
// Printing the values
console.log(pipe_val);
使用以下命令運行index.js文件:
node index.js
輸出:
22
示例2:Filename:index.js
Javascript
// Requiring the module
const collect = require('collect.js');
// Creating collection object
const collection = collect([1, 2,
3, 5, 6, 8, 9, 11, 17, 22]);
// Function call
const pipe_sum = collection.pipe(
element => element.sum());
// Printing the values
console.log(pipe_sum);
使用以下命令運行index.js文件:
node index.js
輸出:
84
相關用法
- node.js Stream readable.pipe()用法及代碼示例
- jQuery deferred.pipe()用法及代碼示例
- Node.js Writable Stream pipe事件用法及代碼示例
- Lodash _.method()用法及代碼示例
- Node.js Http2ServerRequest.method用法及代碼示例
- Node.js http.IncomingMessage.method用法及代碼示例
- Javascript dataView.getInt16()用法及代碼示例
- Javascript RegExp toString()用法及代碼示例
- Node.js URLSearchParams.has()用法及代碼示例
- JavaScript Math cosh()用法及代碼示例
- HTML DOM isEqualNode()用法及代碼示例
- JavaScript Date toLocaleTimeString()用法及代碼示例
- Node.js crypto.createHash()用法及代碼示例
- Node.js writeStream.clearLine()用法及代碼示例
- Node.js fs.link()用法及代碼示例
- JavaScript Math random()用法及代碼示例
- JavaScript Math round()用法及代碼示例
- Javascript toString()用法及代碼示例
- Javascript Number.isInteger( )用法及代碼示例
- Javascript Number.isFinite()用法及代碼示例
- Javascript toFixed()用法及代碼示例
- Javascript toPrecision()用法及代碼示例
注:本文由純淨天空篩選整理自AshokJaiswal大神的英文原創作品 Collect.js pipe() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。