Solved

Insert variable value  into object contained in an array javascript

Posted on 2013-12-18
2
291 Views
Last Modified: 2013-12-18
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
Comment
Question by:badrhino
2 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 39727355
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
 
LVL 1

Author Comment

by:badrhino
ID: 39727376
Rainer,

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

Thanks!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question