How do I remove the [object Object] from my output shown in the console?
I'm looking to print the output without the [Object Object]. Is it possible to achieve this using a ternary operation?
data:[object Object]
text:Data is supplied by Government
link:https://en.wikipedia.org/
This is the code snippet:
const GetData = (obj, step) => {
let padSpace = ""
for (let j=0; j < step; j++) {
padSpace += ''
}
for (let k in obj) {
console.log(padSpace + k + ':' + obj[k])
if (typeof(obj[k]) === "object") {
if (Array.isArray(obj[k])) {
obj[k].forEach(element => {
if (typeof(element === "object")) {
GetData(element, step + 1);
} else {
console.log(padSpace + element)
}
}
);
} else {
GetData(obj[k], step + 1);
}
} else {}
}
I would like the output to be: