Solved

Insert variable value  into object contained in an array javascript

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

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

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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…

735 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