how can I not repeat the code 3 times in this construction?
if (btn=="Daily") {
var Positive = parseInt(data.data.daily.Positive);
var Neutral = parseInt(data.data.daily.Neutral);
var Negative = parseInt(data.data.daily.Negative);
} else if (btn=="Weekly") {
var Positive = parseInt(data.data.weekly.Positive);
var Neutral = parseInt(data.data.weekly.Neutral);
var Negative = parseInt(data.data.weekly.Negative);
} else {
var Positive = parseInt(data.data.monthly.Positive);
var Neutral = parseInt(data.data.monthly.Neutral);
var Negative = parseInt(data.data.monthly.Negative);
}
and a JSON object, I can access data.data[0] but not data.data[0].Positve or data.data[0]['Positive']
Обсуждают сегодня