I am trying to check whether a certain string/value in a JSON is in a list/array but it does not work. What am i doing wrong?
This does work, but I don't just 2012 and Croatia, but all the data from the lists of years and countries:
let countries = ["Croatia", "Italia", "Spain", "Greece", "Isreal", "Turkey"]
let years = ["2012", "2013", "2014", "2015", "2016"]
for (var i = 0; i < 3; i++) {
Object.values(finalDataset[i]).forEach(function(dataSep){
// console.log(dataSep)
for (var i = 0; i < Object.values(dataSep).length; i++){
if ((Object.values(dataSep)[i].Time == "2012") || ((Object.values(dataSep)[i].Year == "2012"))){
if (Object.values(dataSep)[i].Country == "Croatia") {
var nation = Object.values(dataSep)[i].Country
var dataPoints = []
dataPoints.push(Object.values(dataSep)[i].Datapoint)
console.log(nation, dataPoints)
}
}
}
})
}
I tried:
for (var i = 0; i < Object.values(dataSep).length; i++){
if ((Object.values(dataSep)[i].Time in years ) || ((Object.values(dataSep)[i].Year in years))){
if (Object.values(dataSep)[i].Country in countries) {
var nation = Object.values(dataSep)[i].Country
var dataPoints = []
dataPoints.push(Object.values(dataSep)[i].Datapoint)
console.log(nation, dataPoints)
}
}
}
but this doesnt work
Aucun commentaire:
Enregistrer un commentaire