...

View Full Version : Resolved Referencing object array dynamically



mattyod
12-03-2009, 12:22 PM
Hi all,

I'm wondering if what I'm trying to do here is even possible but I'd appreciate your thoughts on it.



<script type="text/javascript">

function test() {
var arrays = {
one: ['1', '2', '3'],
two: ['a', 'b', 'c']
}

var foo = 'one';
alert(arrays.(foo));
}

test();
</script>


I've tried numerous variations of the alert line with evals, brackets and jQuery syntax but always seem to get the error:



XML filter is applied to non-XML value ({one:["1", "2", "3"], two:["a", "b", "c"]})


Which makes me think I'm either attempting something stupid or only missing my target slightly.

The code will be running within a jQuery project up if that helps in any way.

Kor
12-03-2009, 01:16 PM
alert(arrays[foo]);

mattyod
12-04-2009, 02:54 PM
Thanks man, syntax fail from me there :)

Kor
12-04-2009, 03:41 PM
Simple JSON:
http://json.org

glenngv
12-04-2009, 09:14 PM
That's Javascript square bracket notation which is linked in my sig.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum