Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To retrieve the name property of an object that is stored in an array, you would need to access the specific object within the array using its index number, and then access the name property using dot notation or bracket notation.

Here is an example using dot notation:

var myArray = [
  {name: "John", age: 30},
  {name: "Jane", age: 25},
  {name: "Bob", age: 40}
];

var secondObject = myArray[1]; // retrieve second object in array
var nameProperty = secondObject.name; // retrieve name property using dot notation

console.log(nameProperty); // output: "Jane"

Alternatively, you could use bracket notation to access the name property:

var myArray = [
  {name: "John", age: 30},
  {name: "Jane", age: 25},
  {name: "Bob", age: 40}
];

var thirdObject = myArray[2]; // retrieve third object in array
var nameProperty = thirdObject["name"]; // retrieve name property using bracket notation

console.log(nameProperty); // output: "Bob"