I have this object:
const obj = {
key1: false,
key2: "",
key3: undefined,
key4: null
}
Now, I want to use Object.values(obj) so I will get an array of values. But false, undefined & null return as an empty string or in the false case it returns 1 or 0.
So I want to convert the object values to strings.
What will be the best way to do so?
JSON.stringify(obj)will get you most of the way there, butkey3: undefinedis being treated as if it had never been defined at all.Object.values()worksJSON.stringifyObject.values(obj).map(String)if you want an array of strings...?