filter object by key and its items

前端 未结 2 1388
猫巷女王i
猫巷女王i 2021-01-20 21:17

I have an object that I would like to filter it\'s keys..

Im trying to filter the object by an ID, like so:

let myKeys = Object.keys(data).filter(fun         


        
2条回答
  •  梦毁少年i
    2021-01-20 21:25

    Array#filter is expecting a boolean value as return value, you might use this

    let myKeys = Object.keys(data).filter(key => key == vm.system_id);
    

    for getting the keys and then render a new object with the given keys.

    To get all items in a single array, you could collect them with

    let result = myKeys.reduce((r, k) => r.concat(data[k]), []);
    

提交回复
热议问题