Derek Fu Derek Fu - 2 months ago 7
Javascript Question

How to access value from the object within an array?

How can I access Name's value and assign it to an variable?

var arr = [
{Name: "Jason",
Title: "Student",
Image: "asdf",
Status: "Happy"}
];

Answer

Access the element at index 0 of array using bracket notation, then access property name Name of object using dot or bracket notation

var arr = [
    {Name: "Jason", 
    Title: "Student", 
    Image: "asdf", 
    Status: "Happy"}
];

var name = arr[0].Name; // alternatively, `arr[0]["Name"]`