ewan69
asked on
json javascript array question about array referance
Hi,
I am using JSON and eval to get an array of objects, like this:
{"location":[ {"loc_id": "76",
"description": "test",
"company": "testrco",
then eval in javascript so var loc = eval........
The loc_id is a unique no., can i use this as the array no? I want to add to the array and change some of the values "description" for example would be god if i could reference it like
loc.location.loc[76].descr iption instead of loc.location[2].descriptio n where the 2 doesn't relate to anything.
Hope I am making sense....
Thanks,
Ewan
I am using JSON and eval to get an array of objects, like this:
{"location":[ {"loc_id": "76",
"description": "test",
"company": "testrco",
then eval in javascript so var loc = eval........
The loc_id is a unique no., can i use this as the array no? I want to add to the array and change some of the values "description" for example would be god if i could reference it like
loc.location.loc[76].descr
Hope I am making sense....
Thanks,
Ewan
ASKER
Hi moagrius,
Thanks for the quick reply, sorry for not using the right terminoligy, still learing....
I will try your code in a minute thanks, is there a better way of doing things?
I want to be able to periodically update the array elements from a database so i was thinking if the PRIMARY KEY value was used as the array key, using eval i could easily replace the old element with the new.
Is there a better way of doing it?? maybe loop through the array and see if loc.location[i].loc_id == the loc_id of the update, if it does then replace that element with the new one.
not sure if element is the right word, i mean one of the whole objects in the array.
Thanks,
Ewan
Thanks for the quick reply, sorry for not using the right terminoligy, still learing....
I will try your code in a minute thanks, is there a better way of doing things?
I want to be able to periodically update the array elements from a database so i was thinking if the PRIMARY KEY value was used as the array key, using eval i could easily replace the old element with the new.
Is there a better way of doing it?? maybe loop through the array and see if loc.location[i].loc_id == the loc_id of the update, if it does then replace that element with the new one.
not sure if element is the right word, i mean one of the whole objects in the array.
Thanks,
Ewan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help... :)
Open in new window