Solved

Insert variable value  into object contained in an array javascript

Posted on 2013-12-18
2
293 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

751 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