當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Collect.js has()用法及代碼示例

Collect.js中的has()方法用於檢查 key 是否存在於集合中。在JavaScript中,首先將數組轉換為一個集合,然後將該函數應用於該集合。

用法

data.has('key')

Parameters: 

  • Key:此參數保存新的操作值。

返回值:此方法返回布爾值True或False。



以下示例說明了Collect.js中的has()函數

例子1:在此示例中,我們進行收集,然後使用has()函數檢查單個值。

Javascript

// Importing the collect.js module 
const collect = require('collect.js'); 
  
const collection = collect({ 
  name:'GeeksforGeeks', 
  Field:'Education', 
  Address:'Noida', 
}); 
  
console.log(collection.has('name'));

輸出

true

例子2:在此示例中,我們進行了一個收集,然後使用has()函數檢查多個值。

Javascript

// Importing the collect.js module 
const collect = require('collect.js'); 
  
const collection = collect({ 
  name:'GeeksforGeeks', 
  Field:'Education', 
  Address:'Noida', 
}); 
  
console.log(collection.has('name', 'Field', 'Address'));

輸出

true

參考: https://collect.js.org/api/has.html

相關用法


注:本文由純淨天空篩選整理自kaurbal1698大神的英文原創作品 Collect.js has() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。