var b = {
maths:[12,23,45],
physics:[12,23,45],
chemistry:[12,23,45]
};
I want to access array in object b. ie, maths, physics, chemistry . This may be a simple question but i am learning....Thanks
Given the arrays in the object b (note that you have a syntax error in the code you provided)
var b = {
maths: [12, 23, 45],
physics: [12, 23, 45],
chemistry: [12, 23, 45]
};
maths,physics, andchemistryare calledpropertiesof the object stored in variableb
You can access property of an object using the dot notation:
b.maths[0]; //get first item array stored in property maths of object b
Another way to access a property of an object is:
b['maths'][0]; //get first item array stored in property maths of object b
var b = {
maths:[12,23,45],
physics:[12,23,45],
chemistry:[12,23,45]
};
console.log(b.maths);
// or
console.log(b["maths"]);
// and
console.log(b.maths[0]); // first array item
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With