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);
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", "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"]