Looping through an object and changing all values

后端 未结 7 1616
庸人自扰
庸人自扰 2020-12-29 21:42

I\'m having trouble looping through an object and changing all the values to something else, let\'s say I want to change all the values to the string \"redacted\". I need to

7条回答
  •  天涯浪人
    2020-12-29 22:23

    You can also go functional.

    Using Object.keys is better as you will only go through the object properties and not it's prototype chain.

    Object.keys(spy).reduce((acc, key) => {acc[key] = 'redacted'; return acc; }, {})

提交回复
热议问题