Lodash - has 方法



語法

_.has(object, path)

檢查路徑是否為物件的直接屬性。

引數

  • object (Object) − 要查詢的物件。

  • path (Array|string) − 要檢查的路徑。

輸出

  • (boolean) − 如果路徑存在,則返回 true,否則返回 false。

示例

var _ = require('lodash'); 
var object = { 'a': [{ 'b': { 'c': 3 } }] };
var result = _.has(object, 'a');

console.log(result);

result = _.has(object,   ['b']);
console.log(result);

將以上程式儲存在**tester.js**中。執行以下命令來執行此程式。

命令

\>node tester.js

輸出

true
false
lodash_object.htm
廣告
© . All rights reserved.