遍历对象和数组。
Signature:
export declare function traverse(value: any, callback: (value: any, key: string | number, parent: any) => any): void;
Parameter | Type | Description |
---|---|---|
value | any | 要遍历的值 |
callback | (value: any, key: string | number, parent: any) => any | 遍历回调 |
Returns:
void
返回结果
traverse([1, 2, {3: 4}], value => {
console.log(value)
// => 1
// => 2
// => {3: 4}
// => 4
})