0

I want to enter the country name as a variable but I can't.

var interval_1=window.setInterval(function() {
  var name = "USA";
  map.updateChoropleth({
  name : colors(Math.random() * 10),
  });
}, 2000);
Vasim
  • 3,052
  • 3
  • 35
  • 56

1 Answers1

1

What you want is to use a variable as a key in a JavaScript object literal. This has already been answered here: Using a variable for a key in a JavaScript object literal

This would give the result you expect:

var interval_1=window.setInterval(function() {
    var name = "USA";
    var country = {}
    country[name] = colors(Math.random() * 10)
    map.updateChoropleth(country);
}, 2000);
Community
  • 1
  • 1
burningfuses
  • 1,779
  • 1
  • 11
  • 11