Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Return object result

I need to get the result of this object, I’ve tried json.count(id_reported) and json['count(id_reported)'] but none worked.

const json = { 
  'count(id_reported)': 21 
};
    
//console.log(json.count(id_reported));
console.log(json['count(id_reported)']);

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In Javascript, Typescript and so in Express in the end, its easy to handle such things.

var myObject = { 
  'count': 21 
}

myObject = JSON.parse(myObject);
console.log(myObject.count);

The JSON.parse is only needed, if you object is a string. Is it a Javascript object you do not need to parse.

The count(id_reported) part I don’t understand. If your object looks like this in the end:

{
  count(1): 1,
  count(2): 2,
}

and you don’t know the structure at all you can use a for loop:

for (let data in myObject) {
  console.log(data); // data will be the key; so count(1) as example
}

See the in keyword in the for loop. This will give you the key. The on keyword otherwise gives the object in an array as example.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading