Best way to store a key=>value array in JavaScript?

前端 未结 7 1829
借酒劲吻你
借酒劲吻你 2020-11-28 00:27

What\'s the best way to store a key=>value array in javascript, and how can that be looped through?

The key of each element should be a tag, such as

相关标签:
7条回答
  • 2020-11-28 01:23

    I know its late but it might be helpful for those that want other ways. Another way array key=>values can be stored is by using an array method called map(); (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) you can use arrow function too

     
        var countries = ['Canada','Us','France','Italy'];  
    // Arrow Function
    countries.map((value, key) => key+ ' : ' + value );
    // Anonomous Function
    countries.map(function(value, key){
    return key + " : " + value;
    });

    0 讨论(0)
提交回复
热议问题