Javascript Object 'location' Pointer?

Associate
Joined
26 Nov 2004
Posts
1,480
Location
Gran Canaria
Hi

It maybe I'm barking up the wrong tree here but i'll try and explain what I'm trying to do.

I'm trying to update an object, rather an element within an object, and would like to be able to store the location as a variable.

For example:

ref = Object[cat1][cat2][cat3];

I don't wish ref to store the contents of the referenced data with the object, rather the location within its structure. This would allow me to update the Object after some iteration.

Instead of:

Object[cat1][cat2][cat3] = data;

(which I've lost through further iteration)

ref = data;

I'm kinda tying myself in knots and would really like if someone could point me in the right direction. Thanks in advance!
 
So still having this problem. Is there an alternative?

For example, it would be convenient if I could do this:
Code:
function objBuild (someIds){
  var st = '';
  for (var i in someIds){
     st = st + "[" + someIds[i] + "]";
  }
  obj+someIds = newData;
}
But of course this obj+someIds results in a string, rather than a reference to an object within an object, or object of object of object etc.

Alternately I considered:

Code:
function iter(obj, selCats, data){
  for (var x = 0; x < obj.length; x++){
    if (obj[x].id==selCats[x]){
      iter(obj[x], selCats, data);
      break;
    } 
  }
  obj[selCats[x]] = data;
}

But this would leave the original object untouched.

If this isn't clear please let me know and i'll try explain better.
 
Last edited:
Thanks for that!

Looks great. I think it needs some modification to work recursively but should be me on the right track. Cheers!
 
Back
Top Bottom