vtils

Home > utils > traverse

traverse() function

遍历对象和数组。

Signature:

export declare function traverse(value: any, callback: (value: any, key: string | number, parent: any) => any): void;

Parameters

Parameter Type Description
value any 要遍历的值
callback (value: any, key: string | number, parent: any) => any 遍历回调

Returns:

void

返回结果

Example

traverse([1, 2, {3: 4}], value => {
  console.log(value)
  // => 1
  // => 2
  // => {3: 4}
  // => 4
})