vue 深度拷贝 除去空的参数

// 去除数组里面为空的属性及子数组
export function deepCopy (source) {
var result = []
//var result = {}
for (var key in source) {
if (source[key] instanceof Array) {
if (source[key].length > 0) {
result[key] = typeof source[key] === 'object'
? deepCopy(source[key])
: source[key]
}
} else {
if (source[key]) {
result[key] = typeof source[key] === 'object'
? deepCopy(source[key])
: source[key]
}
}
}
return result
}
posted @ 2017-12-20 11:37    阅读(1269)  评论(0编辑  收藏  举报