Categories
JavaScript Answers

How to access and process nested objects, arrays, or JSON with JavaScript?

Spread the love

To access and process nested objects, arrays, or JSON with JavaScript, we use object methods.

For instance, we write

const obj = {
  a: 1,
  b: 2,
  c: 3,
};

console.log(Object.keys(obj));
console.log(Object.values(obj));
console.log(Object.entries(obj));

to call Object.keys to get the property keys of obj in an array.

We call Object.values to get the property values of obj in an array.

And we call Object.entries to get the property key-value pair arrays in obj in an array.

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 *