Use Object.keys:

var foo = {
  'alpha': 'puffin',
  'beta': 'beagle'
};

var keys = Object.keys(foo);
console.log(keys) // ['alpha', 'beta'] 
// (or maybe some other order, keys are unordered).

This is an ES5 feature. This means it works in all modern browsers but will not work in legacy browsers.

The ES5-shim has a implementation of Object.keys you can steal

Answer from Raynos on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › keys
Array.prototype.keys() - JavaScript - MDN Web Docs
July 20, 2025 - const array = ["a", "b", "c"]; const iterator = array.keys(); for (const key of iterator) { console.log(key); } // Expected output: 0 // Expected output: 1 // Expected output: 2 ... A new iterable iterator object.
Discussions

jquery - javascript get key name from array of objects - Stack Overflow
Use map() and return the first key the object. You can get keys using Object.keys() More on stackoverflow.com
🌐 stackoverflow.com
Getting key of each object inside array of objects into an array: Javascript - Stack Overflow
You can simply use .map() to open the array and then use Object.keys to return the key from the object. More on stackoverflow.com
🌐 stackoverflow.com
July 19, 2019
How to get a key from array of objects by its value Javascript - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
November 8, 2018
Generate an Array of All Object Keys with Object.keys()
Tell us what’s happening: I have a good understanding on how to use Object.keys() with 1 object; however, I want to understand how this would work in a nested array with 2 or more objects. **Your code so far** let u… More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
3
0
August 11, 2022
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
How to access a specified object's key value in an array of objects? - JavaScript - The freeCodeCamp Forum
May 29, 2022 - I need to access the value of name key of the first object in this 2 object array. Using map() returns the value of both objects. How can I access the first one only? let x = [ {name : 'A', age: 20}, {name : 'B', age: 21} ] console.log(x.map(a => a.name))
🌐
Designcise
designcise.com › web › tutorial › how-to-extract-specific-keys-values-from-an-array-of-objects-in-javascript
JS Extract Specific Key's Values From Array of Objects - Designcise
June 1, 2021 - In ES6+, you can shorten this syntax by using the arrow function and unpacking the relevant object property passed to the provided callback function, for example, like so: // ES6+ const names = users.map(({ name }) => name); console.log(names); // ['John', 'Wayne', 'David'] If you're unable to support a minimum ES5, then you may simply iterate over the array using a for loop for example, and extract object values into a new array in the following way:
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Object › keys
Object.keys() - JavaScript - MDN Web Docs
// Basic array const arr = ["a", "b", "c"]; console.log(Object.keys(arr)); // ['0', '1', '2'] // Array-like object const obj = { 0: "a", 1: "b", 2: "c" }; console.log(Object.keys(obj)); // ['0', '1', '2'] // Array-like object with random key ordering const anObj = { 100: "a", 2: "b", 7: "c" }; console.log(Object.keys(anObj)); // ['2', '7', '100'] // getFoo is a non-enumerable property const myObj = Object.create( {}, { getFoo: { value() { return this.foo; }, }, }, ); myObj.foo = 1; console.log(Object.keys(myObj)); // ['foo']
🌐
TutorialsPoint
tutorialspoint.com › article › retrieve-key-and-values-from-object-in-an-array-javascript
Retrieve key and values from object in an array JavaScript
March 15, 2026 - const students = [ {name: 'Alice', grade: 'A', subject: 'Math'}, {name: 'Bob', grade: 'B', subject: 'Science'} ]; students.forEach((student, index) => { console.log(`\nStudent ${index + 1}:`); Object.entries(student).forEach(([key, value]) => { console.log(` ${key}: ${value}`); }); }); Student 1: name: Alice grade: A subject: Math Student 2: name: Bob grade: B subject: Science · The time complexity is O(n × m), where n is the number of objects in the array and m is the average number of properties per object.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › find-specific-key-value-in-array-of-objects-using-javascript
Find specific key value in array of objects using JavaScript
const obj = { "LAPTOP": [{ "productId": "123" }], "DESKTOP": [{ "productId": "456" }], "MOUSE": [{ "productId": "789" }, { "productId": "012" }], "KEY-BOARD": [{ "productId": "345" }] }; We are required to write a JavaScript function that takes in one such object as the first argument, and a key value pair as the second argument.
🌐
Codeymaze
codeymaze.com › home › javascript – get keys of each object inside an array of objects
How to Get the Keys of Each Object Inside an Array of Objects in JavaScript
February 4, 2025 - let obj = [{"a": 1}, {"b" : 2}, {"c" : 3}]; let result = Object.keys(Object.assign( {}, ...obj )); console.log(result); ... Array.flatMap()Array.flatMap() is a method in JavaScript that both maps and flattens an array.
🌐
Stack Overflow
stackoverflow.com › questions › 53205060 › how-to-get-a-key-from-array-of-objects-by-its-value-javascript
How to get a key from array of objects by its value Javascript - Stack Overflow
November 8, 2018 - var arr = [{ 'key1': 'val1'}, { 'key2': 'val2'}]; function getKey(data,value) { let keys=[]; data.forEach(function(element) { for (key in element) { if(element[key]==value) keys.push(key); } }); return keys } console.log(getKey(arr, 'val1')) ...
🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
Generate an Array of All Object Keys with Object.keys()
August 11, 2022 - Tell us what’s happening: I have a good understanding on how to use Object.keys() with 1 object; however, I want to understand how this would work in a nested array with 2 or more objects. **Your code so far** let users = { Alan: { age: 27, online: false }, Jeff: { age: 32, online: true }, Sarah: { age: 48, online: false }, Ryan: { age: 19, online: true } }; function getArrayOfUsers(obj) { // Only change code below this line return Object.keys(obj); // Only change code abov...
🌐
Flexiple
flexiple.com › javascript › key-value-javascript
JavaScript: Obtain key-value pairs in an array
March 14, 2022 - Let us first store the previously extracted keys & values in separate arrays · var keys = ["one", "two", "three"]; var values = [1, 2, 3]; In this method we store the elements from the “keys” array & the corresponding values from the ...
🌐
W3Schools
w3schools.com › jsref › jsref_keys.asp
JavaScript Array keys() Method
// Create an Array const fruits = ["Banana", "Orange", "Apple", "Mango"]; // List the Keys let text = ""; for (let x of Object.keys(fruits)) { text += x + "<br>"; } Try it Yourself » · Array Tutorial · Array Const · Basic Array Methods · Array Search Methods · Array Sort Methods · Array Iteration Methods · keys() is an ECMAScript6 (ES6 2015) feature. JavaScript 2015 is supported in all browsers since June 2017: ❮ Previous JavaScript Array Reference Next ❯ · ★ +1 · Sign in to track progress · REMOVE ADS · PLUS · SPACES · GET CERTIFIED ·
🌐
Medium
codeymaze.medium.com › how-to-get-the-keys-of-each-object-inside-an-array-of-objects-in-javascript-codeymaze-fd7ca1306e30
How to get the keys of each object inside an array of objects in Javascript — Codeymaze | by CodeyMaze | Medium
September 20, 2024 - ... 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.
🌐
Latenode
community.latenode.com › other questions › javascript
How to retrieve specific key values from an array in JavaScript? - JavaScript - Latenode Official Community
November 30, 2024 - I am trying to extract certain key values, specifically ‘serviceCode’, from an array of objects in JavaScript. Can someone guide me on how to achieve this? Below is a sample code snippet: var data = { "0": JSON.stringify({"carrier":"ups","service":"ground","cost":"28.66"}), "1": JSON.stringify({"carrier":"ups","service":"second_day","cost":"69.72"}), "2": JSON.stringify({"carrier":"ups","service":"next_day","cost":"76.62"}) }; var result = []; Object.keys(data).forEach(function(key...