Skip to content

Instantly share code, notes, and snippets.

@jovey-zheng jovey-zheng/merge.js
Created May 20, 2016

Embed
What would you like to do?
merge array based on lodash.
var _ = require('lodash');
module.exports = function (source, target) {
var joinArrays = function (a, b) {
if (_.isArray(a) && _.isArray(b)) {
return a.concat(b);
};
if (_.isPlainObject(a) && _.isPlainObject(b)) {
return _.merge(a, b, joinArrays);
};
return a;
}
return _.merge(target, source, joinArrays);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.