I have created a multidimensional array for a jobs feed like so:
var jobs = [
["JOB222" , "Painter"],
["JOB333" , "Teacher"],
["JOB444" , "Delivery Driver"],
];
I can access the array using the index number
alert( jobs[2][1] ); // Alerts Delivery Driver
If I set the reference number manually, I can loop through the array to find a match.
var viewingJobRef = "JOB333";
for (var i=0;i<jobs.length;i++) {
if (jobs[i][0] == viewingJobRef) {
alert(jobs[i][1]); // This will alert Teacher
}
}
So my question is, is it possible to access the array directly and not use a loop?
var viewingJobRef = "JOB333";
alert( jobs[viewingJobRef][1] ); // I want this to alert Teacher
Firefox error console says: jobs[viewingJobRef]is undefined, how do I do it?