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


Lodash _.toPath()用法及代碼示例

Lodash _.toPath()方法用於將給定值轉換為屬性路徑數組。

用法:

_.toPath(value)

參數:此方法接受如上所述和以下描述的單個參數:

  • value:需要轉換為路徑數組的值。

返回值:新的屬性路徑數組。

範例1:



Javascript

// Requiring the lodash library   
const _ = require("lodash");             
    
// Use of _.toPath() method  
let gfg = _.toPath('geeks.for.geeks');  
        
// Printing the output   
console.log(gfg);

輸出:

["geeks", "for", "geeks"]

範例2:

Javascript

// Requiring the lodash library   
const _ = require("lodash");             
    
// Use of _.toPath() method  
let gfg = _.toPath('geeks[0].for[1].geeks[2]');  
        
// Printing the output   
console.log(gfg);

輸出:

["geeks", "0", "for", "1", "geeks", "2"]

相關用法


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