I don’t figure it out, how to clear each value of each key inside an object.
The result should be like this.
const initialObject = { a: "valueA", b: "valueB", c: "valueC" }; const finalObject = { a: "", b: "", c: "" };
I’m using Typescript.
Thank you for your help.
Advertisement
Answer
Map the keys to an array of [key, ""]
and then convert to an object using Object.fromEntries()
:
const initialObject = {a: "valueA", b: "valueB", c: "valueC"} const finalObject = Object.fromEntries( Object.keys(initialObject) .map(key => [key, ""]) ) console.log(finalObject)