You can use an array of objects:
var items = [ {id:10, producer:'Ford'}, {id:30, producer:'Rover'}, {id:11, producer:'BMW'}, {id:1, producer:'Fiat'}, {id:4, producer:'Renault'}, {id:2, producer:'Mitsubishi'}, ] // or, starting from your two arrays: var items = []; for (var i=0; i<ids.length && i<producers.length; i++) items[i] = {id:ids[i], producer:producers[i]};
Then you can sort that array by id:
items.sort(function(a, b){ return a.id-b.id; });
...and iterate it with a for-loop.
Another solution would be an iterator array, to loop over an id<->producer object (weirdo) in the correct order:
var weirdo = {"10":"Ford","30":"Rover",...}; var ids = Object.keys(weirdo); // if not already built somewhere ids.sort(function(a,b){return a-b;}); // sort numeric // loop: for (var i=0; i<ids.length; i++) { var id=ids[i], producer=weirdo[id]; ... }
weirdoto be an object at all, if you have numerical keys anyways. Why don't you just create a copy ofproducers?weirdo, why (you think) it must be an object, etc., then we could help you better. Otherwise the answer is that you can't do it.