0

I'm new to Javascript objects and Jquery and I have no clue how I do something like this:

 series: {
                        regions: [{
                            values: {
                                for(i = 0; i < 10; i++){
                                    [countryname[i]] : countrycolor[i]
                                 }
                                [countrynames] : countrycolor,
                            }
                        }]
                    }

How do I make the for loop basically print out the country names and countrycolors that I have in an array.

Im using jvectormap and the full code which im using right now for the map is:

            var countrynames = "<?php if (isset($countryname)) {echo $countryname;}; ?>";
            var countrycolor = "<?php if (isset($countrycolor)) {echo $countrycolor;}; ?>";
            $('#world-map').vectorMap({
                map: 'world_mill',

                onRegionClick: function (event, code) {
                    window.location.href = "country.php?id=" + code;
                },


                series: {
                    regions: [{
                        values: {
                            [countrynames] : countrycolor,
                        }
                    }]
                }
            });

1 Answer 1

0

You could use reduce[1] function to achive what you want on plain javascript

{
  values: countrynames.reduce(function(result, country, index) {
    result[country] = countrycolor[index];
    return result;
  }, {});
}

[1] - https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.