I have an array and I'm not sure how to access certain keys. What I'm trying to accomplish is simply target certain keys/values in the array. Here's a sample of my array.
var jobs = [ { // hunting name: 'Hunting', available: [ { name: 'Housemate', description: 'You stick around the cabin of the hunters. You are the lowest class of the hunters.', salary: 10 }, { name: 'Fetcher', description: 'You are the fetcher of the clan. You gather leather, resources, and skin leather.', salary: 15 }, { name: 'Hunter', description: 'You are a basic hunter of the clan. You hunt for food, meat, and leather.', salary: 25 }, { name: 'Elder', description: 'You are a elder of the clan. You are respected among many, and may ask hunters for arrons.', salary: 0 } ], // construction name: 'Construction', available: [ { name: 'Builder', description: 'You are a builder. You are the lowest class of the construction tier.', salary: 45 }, { name: 'Driver', description: 'You are a driver. You do the fetching and gathering of resources.', salary: 55 }, { name: 'Engineer', description: 'You are a engineer. You do the wiring and electrical work in the construction.', salary: 65 }, { name: 'Overseer', description: 'You are the overseer. You watch over the construction and give orders.', salary: 80 } ], } ]; Now keep in mind that I have multiple arrays in one array. Here I try to access the Hunter job category, the Fetcher job, and the construction Engineer salary.
alert(jobs.'Hunting'); // gives 'missing name after . operator' error alert(jobs.name[0]); // gives 'name is not defined' error alert(jobs.available.'Fetcher'); //same error as number 1 alert(jobs.available.salary[0]) // gives available is not defined error How can I access those variables?
jobs[0].name === 'hunting'.jobsis an array and the first item is an object. You can't select by the value of a property either.{and}...}, {at the// constructionline.