Accessing Object Properties and Array Elements
You'll learn: How to reach into objects and arrays from within JSX using JavaScript's dot and bracket notation.
The Core Idea
JSX's curly braces let you write any valid JavaScript expression. That means you can access nested data structures just like you would in regular JavaScript—using dot notation (object.property) or bracket notation (array[0] or object['key']).
Think of curly braces as a window into JavaScript-land. Once you're inside them, all normal JavaScript rules apply, including drilling into data structures.
Dot Notation for Objects
const user = {
name: "Sarah",
age: 28
};
const element = <h1>Welcome, {user.name}!</h1>;
// Renders: Welcome, Sarah!
You're reaching through the user object to grab its name property, exactly like JavaScript outside JSX.
Bracket Notation for Arrays
const colors = ["red", "green", "blue"];
const element = <p>First color: {colors[0]}</p>;
// Renders: First color: red
Array indexes work identically inside JSX interpolation.
Deeply Nested Access
const data = {
users: [
{ name: "Alex", score: 95 }
]
};
const element = <p>Top scorer: {data.users[0].name}</p>;
// Renders: Top scorer: Alex
Chain as many property accesses and array indexes as you need—it's just JavaScript.
Key Takeaway: Inside JSX curly braces, use dot notation and bracket notation exactly as you would in regular JavaScript to access object properties and array elements. The interpolation syntax doesn't change how data access works.