TehShrike/deepmerge

How to delete an element from an array with deepmerge.

Opened this issue · 1 comments

Hi, I would like to be able to remove a value from my array but with deepmerge the array values only add up. Does anyone have an idea how to solve this problem?

const dp = require('deepmerge');
const a = ['test0', 'test1', 'test2'];
const b = ['test1'];
dp(a, b); // outpout => ['test0', 'test1', 'test2', 'test1'] or I want ['test0', 'test2']
const options = {
  arrayMerge: (x, y) => {
    const result = x.slice();
    for (const element of y) {
      const index = x.indexOf(element);
      if (index >= 0) {
        result.splice(index, 1);
      }
    }
    return result;
  }
};

const result = deepmerge(a, b, options);