I have the following JsonObject
let jsonObject = {
"augmentedReality": {
"enabled": false,
"augmentedRealitySettings" : [
{
"assetId": 7
}
]
}
}
I am have written a recursive function that looks the following
isAssetId(jsonObject: any) {
for (let key in jsonObject) {
if (typeof jsonObject[key] === "object") {
jsonObject[key] = this.isAssetId(jsonObject[key]);
} else {
if(key=='assetId'){
jsonObject[key]=3;
}} }
return jsonObject;
}
My goal is to change the assetId wherever it exists in the jsonObject. This JSON is just an example, while assetId could be far in the deeper. The problem with the code is that when it's successfully executed it returns the following JSON object I call the function with the following:
jsonObject= isAssetId(jsonObject);
console.log(jsonObject);
and I get the following results.
{
augmentedReality: { enabled: false, augmentedRealitySettings: [
[Object] ] }
}
The Object
should show the data it has not the object.
I cannot figure out what seems to be the problem. Any help would be appreciated?
UPDATE:
I wrote the code into the following site
here
Weirdly it's working fine here, but it does not work on my typescript on NestJs
? Now what is the reason?