ES6 merge object

Object.assign (target,. Sources) is to merge all the sources of the latter into target,. Is there any way to merge only the key that is not available in key, target with target?

Jul.27,2021

for reference. Consistent with the Object.assign behavior, except for the function length , this is not east-west compatible, so it does not need to be consistent; and there is no copy of Symbol .

function merge(target, src) {
    const result = {...target}
    Object.keys(target).forEach(key => {
        if (target.hasOwnProperty(key)) {
            result[key] = src[key]
        }
    })
    return result
}
Menu