How do you access a key named "foo" of the 5th element of an array that is the 2nd element of another array that is the value of a hash key named "baz"?
can you provide the basic examples?
You want to use an object:
var obj = {
foo: {
bar: "yo"
}
}
console.log(obj["foo"]["bar"]);
// Or you could do this
var obj = {};
obj["foo"] = {};
obj["foo"]["bar"] = "yo";
console.log(obj["foo"]["bar"]);
Note the order of an object is not guaranteed and can change depending on the interpreter / compiler.
An array in JavaScript is just an object with numerical indices (With some specific methods - see comment below). In fact pretty much everything in JavaScript is an object.
indexOf) and properties (e.g. length) that you don't get on plain objects.How do you access a key named "foo" of the 5th element of an array that is the 2nd element of another array that is the value of a hash key named "baz"?
variableName["baz"][1][4]["foo"];
Would get you "The value here" from
var variableName = { baz: [0, [0, 1, 2, 3, { foo: "The value here" }]] };
and here's a jsFiddle to play with
{ foo: "bar" }, only don't expect properties to always have the same "index" in an object.{foo: "bar", baz: "foobar"}, but they are unordered.JS Object