Solved

Insert variable value  into object contained in an array javascript

Posted on 2013-12-18
2
286 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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'…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now