Chartjs-How can i grab a property from an array of JSON objects to use the values of that property as a labels in my chart?

0👍

If I understood you correctly, that is your answer

let json = [{
    "end_year": "",
    "intensity": 6,
    "sector": "Energy",
    "published": "January, 09 2017 00:00:00",
    "country": "United States of America",
  },
  {
    "end_year": "",
    "intensity": 6,
    "sector": "Two",
    "published": "January, 09 2017 00:00:00",
    "country": "Canada",
  }
];

let sectors = json.map((obj) => {
  return obj.sector
})
let countries = json.map((obj) => {
  return obj.country
})
console.log('sectors:', sectors)
console.log('countries:', countries)

Leave a comment