Categories
JavaScript Answers

How to access first element of JSON object array with JavaScript?

Spread the love

To access first element of JSON object array with JavaScript, we use index 0.

For instance, we write

const req = { events: [{ event: "inbound", ts: 1426249238 }] };
console.log(req.events[0]);

to get the req.events array property and get its first item with index 0 in the square brackets.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *