I need the output as
{ 'US-CA': '#084365',
'US-TX': '#084365',
'US-CO': '#00a2e8',
'US-NM': '#00a2e8',
'US-WY': '#00a2e8',
'US-NE': '#00a2e8'
}
For this I used the following code:
var output = [];
$('.vectordata').find('.varc').each(function(i){
var t = $(this);
regioncode = t.find('.regioncode').val();
color = t.find('.color').val();
var obj2 = {}
obj2[regioncode] = color;
output.push(obj2);
}
But the output I received is
Please help me fix the dynamic object creation
you dont need the array just put it in the object
var output = {};
$('.vectordata').find('.varc').each(function(i){
var t = $(this);
regioncode = t.find('.regioncode').val();
color = t.find('.color').val();
output[regioncode] = color;
}