Object.keys(sample)
.map(key => ({key: key, fixed: key.split('__')[1], value: sample[key]}))
.filter(item => filterFunction(item.fixed))
.reduce((p, c) => (p[c.key] = c.value) && p, {})
- Take the keys with
Object.keys
. map
new array of objects with the origin key, value, and fixed key.filter
the array with your ‘filterFunction’.- Create new object with filter keys, using
reduce
.
solved want to split the key and filter after __ key in object key