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

object to String modification in javascript

i got object like this.

Object {
  "company": "984",
  "id": "1",
}

i want to access company and id individually.

The result should look like this

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

"984"
"1"

How can i achieve these?Thanks.

>Solution :

Object.values will give you an array of the values

const obj = {
  "company": "984",
  "id": "1",
};

console.log(Object.values(obj));

You can of course assign this array to a variable and then access the values individually

const vals = Object.values(obj);
console.log(vals[0]); /// "984"
console.log(vals[1]); /// "1"
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