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

Extract only key names from JSON in array format using nodejs

How to get JSON data key names in a array format using nodejs?

I’ve tried the following but it returns object. But I want an array so I can store it in a varaible.

const jsondata = [{ "name": "StorageType", "value": "AllStorageTypes" }, { "name": "BucketName", "value": "testing" }]

Object.keys(jsondata).forEach(function(key) {
  var value = jsondata[key];
  console.log(value)
});

output:

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

{ name: 'StorageType', value: 'AllStorageTypes' }
{ name: 'BucketName', value: 'testing' }

Expected output:

["StorageType", "BucketName"]

>Solution :

Try this

const jsondata = [{ "name": "StorageType", "value": "AllStorageTypes" }, { "name": "BucketName", "value": "testing" }]

const arrayData = jsondata.map(item => item.name)
console.log(arrayData)
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