Multi-dimensional array in Javascript (Or something like it) -
a site working on require list of makes (car manufacturers) listed in 1 column, models of specific create appear in column right of when create clicked, , proceed list details available cars of model in div on right-hand side. bulk of code completed, i've needed alter array 1 filled object literals having array object literals within array. below code have been trying work out (the arrays only, can handle rest of it) , can't figure out right.
any help appreciated.
<div id="test"></div> <script type="text/javascript"> var inv=new array(); inv["aston martin"]=new array( ["dbs"]=new array( {"year":2009;"price":"$191,400"}, {"year":2006,"price":"$160,000"}); ["db5"]=new array( {"year":2000,"price":"$80,500"}, {"year":1996,"price":"$100,600"}); ); document.getelementbyid('test').innerhtml = inv["aston martin"]["dbs"][1].price; </script>
in code, inv
should not array, object.
var inv = {};
you can not utilize strings array index, using object looks fine in case.
same thing sec level.
var inv = {}; inv["aston martin"] = { "dbs": new array( {"year":2009;"price":"$191,400"}, {"year":2006,"price":"$160,000"}), "db5": new array( {"year":2000,"price":"$80,500"}, {"year":1996,"price":"$100,600"}) };
or simpler:
var inv = {}; inv["aston martin"] = { "dbs": [ {"year":2009;"price":"$191,400"}, {"year":2006,"price":"$160,000"} ], "db5": [ {"year":2000,"price":"$80,500"}, {"year":1996,"price":"$100,600" ] };
javascript
No comments:
Post a Comment