More idiomatic way to move item from one dict value(list) to another? Is there a more idiomatic way to handle the following scenario? I'm open to lodash, etc. if needed. This does what I want, but I feel that there is probably a shortcut I'm missing:

const migrateValues = (obj, srcKey, destKey, value) =&gt; {
    updatedSrc = [];
    obj[srcKey].forEach(x =&gt; {
        if (x !== value) {
            updatedSrc.push(x);
        }
    });
    obj[destKey].push(value);
    obj[srcKey] = updatedSrc;
    return obj;
}

obj = {
    "key1": [1, 2, 3],
    "key2": [4, 5, 6],
    "key3": [7, 8, 9],
    "key4": [10, 11, 12]
};
valueToMove = 11;
srcKey = "key4";
destKey = "key2";

console.log(obj);
console.log(migrateValues(obj, srcKey, destKey, valueToMove));
I would propose something like so (given that you have assumed no dupes, etc)

function migrateValues(obj, srcKey, destKey, value) {
    return {
        ...obj,
        [srcKey]: obj[srcKey].filter(w =&gt; w !== value),
        [destKey]: obj[destKey].concat(value)
    };
}


We spread obj, and then overwrite the srcKey and destKey properties.

There are several reasonable ways to make obj[srcKey].filter and obj[destKey].concat avoid TypeErrors, which is best is dependent on what you have planned for the function.