How to get the keys of each object inside an array of objects in Javascript — Codeymaze

CodeyMaze
2 min readDec 22, 2023

--

You can get the keys of each object inside an array of objects in many ways. In this article, we will cover two methods.

Methods to get the keys of each object

  • Using Object.keys() and Object.assign()
  • Using Array.flatMap() and Object.keys()

Method 1: Using Object.keys() and Object.assign()

Object.keys() — Object.keys() is a javascript method that returns an array of the enumerable property names of the given object. In other words, it extracts the keys of an object and returns them as an array. The order of the keys in the array is determined by the order in which they are defined in the object.

Object.assign() — Object.assign() is a method in JavaScript used to copy the values of all enumerable properties from one or more source objects to a target object. It returns the modified target object.

Output of the above will be -

Read more at: https://codeymaze.com/how-to-get-the-keys-of-each-object-inside-an-array-of-objects-in-javascript/

Originally published at https://codeymaze.com on December 22, 2023.

--

--

CodeyMaze
CodeyMaze

Written by CodeyMaze

Crafting Solutions Through Code & Words https://codeymaze.com Feel free to follow me :)

No responses yet