Lodash - at 方法



語法

_.at(object, [paths])

根據物件的路徑建立值陣列。

引數

  • object (Object) − 要迭代的物件。

  • [paths] (...(string|string[])) − 要選擇的屬性路徑。

輸出

  • (Array) − 返回選取的值。

示例

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

console.log(_.at(object, ['a[0].b.c', 'a[1]']));

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

命令

\>node tester.js

輸出

[ 3, 4 ]
lodash_object.htm
廣告
© . All rights reserved.