/ * *
-
Deep copy reference data (function data is not copied)
-
@data [Object, Array]
-
@isdeep Boolean Specifies the default deep copy
-
#return [Object, Array] */
export function getDeepCopyData(data = {}, isDeep = true){ if(data && typeof data === 'object'){ const obj = data instanceof Array ? [] : {}; for(const [key, value] of Object.entries(data)){ obj[key] = (isDeep && typeof value === 'object') ? getDeepCopyData(value) : value; } return obj; } return data; } Copy the code
/ * *
-
Deeply traverses an object, converting all arrays in the object to a string delimited by the specified symbol
-
@obj Object Indicates the Object to be traversed
-
@joinstr String An array delimited symbol
-
@excludeKeys Array Specifies the excluded key name
-
#return Object */
export function walkSplitInObj(obj, excludeKeys = [], joinStr = ','){ if(! obj || typeof obj ! == 'object') return obj; return Object.entries(obj).reduce((total, [key, value]) => ({ ... total, [key]: ! Array.isArray(value) ? walkSplitInObj(value, excludeKeys, joinStr) : ! excludeKeys.includes(key) ? value.join(joinStr) : value }), {}) }Copy the code