Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

Insert variable value into object contained in an array javascript

I'm trying to insert a variable into an objects property value that is contained in an array.  
This will be easier to understand if I just show you what I'm trying to do.  I have an array of objects declared as:
var map_config = {
        'map_2':{
		'namesId':'AK',
		'name': 'ALASKA',
		'data':Population of Alaska',
		'upcolor': '#a0a0a0',
		'overcolor':'#99CC00',
		'downcolor':'#993366',
		'enable':false,
	},
	'map_3':{
		'namesId':'AZ',
		'name': 'ARIZONA',		
		'data':Population of Arizona',
		'upcolor':'#EBECED',
		'overcolor':'#99CC00',
		'downcolor':'#993366',
		'enable':true,
	}, ....

Open in new window


For each object in the array (50--one for each state), I'm trying to modify the data property by doing something like this:

 'map_2':{
		'namesId':'AK',
		'name': 'ALASKA',
		'data':Population of Alaska' + variable1,
		'upcolor': '#a0a0a0',
		'overcolor':'#99CC00',
		'downcolor':'#993366',
		'enable':false,
                }

Open in new window


where variable1 is a variable of type string which is created at the server and pushed out to the client (in this case I'm using ClientScript.RegisterArrayDeclaration).  The variable names are not dynamic so I can hardcode the variable name in (e.g. variable1 not variable i)

The above syntax is not working.  Any suggestions?
0
badrhino
Asked:
badrhino
1 Solution
 
Rainer JeschorCommented:
Hi,
have not tried it in a sample but I guess you are just missing the opening quote '
 'map_2':{
		'namesId':'AK',
		'name': 'ALASKA',
		'data':'Population of Alaska' + variable1,
		'upcolor': '#a0a0a0',
		'overcolor':'#99CC00',
		'downcolor':'#993366',
		'enable':false,
                }

Open in new window

Or is the data property not a string but another object?
HTH
Rainer
0
 
badrhinoAuthor Commented:
Rainer,

Nice catch.  Been looking at that for a while now and never saw that....

Thanks!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now