Javascript array - merge two arrays into one
Posted
by
estrar
on Stack Overflow
See other posts from Stack Overflow
or by estrar
Published on 2012-11-21T10:46:51Z
Indexed on
2012/11/21
11:00 UTC
Read the original article
Hit count: 226
I have two arrays, one with name of the country and one with the currency type. I would like to merge these together and use the country key instead of the currencies array. What would be the best way to accomplish this?
This is what my code looks like now:
var country = new Array();
country["SEK"] = 'Sweden';
country["USD"] = 'United states';
var currencies = ["SEK","USD"];
var options = '';
for (var i = 0; i < currencies.length; i++) {
options += '<option value="' + currencies[i] + '" id="' + currencies[i] + '">' + currencies[i] + ' (' + country[currencies[i]] + ')</option>';
}
© Stack Overflow or respective owner