[removed] filter() for Objects

前端 未结 16 952
心在旅途
心在旅途 2020-11-22 15:23

ECMAScript 5 has the filter() prototype for Array types, but not Object types, if I understand correctly.

How would I implemen

16条回答
  •  孤独总比滥情好
    2020-11-22 15:52

    I use this when I need it:

    const filterObject = (obj, condition) => {
        const filteredObj = {};
        Object.keys(obj).map(key => {
          if (condition(key)) {
            dataFiltered[key] = obj[key];
          }
        });
      return filteredObj;
    }
    

提交回复
热议问题