How to filter keys of an object with lodash?

前端 未结 5 1154
野趣味
野趣味 2020-11-28 23:51

I have an object with some keys, and I want to only keep some of the keys with their value?

I tried with filter:

5条回答
  •  天命终不由人
    2020-11-29 00:42

    Just change filter to omitBy

    const data = { aaa: 111, abb: 222, bbb: 333 };
    const result = _.omitBy(data, (value, key) => !key.startsWith("a"));
    console.log(result);

提交回复
热议问题