tl;dr

  1. In ECMAScript 2017, just call Object.entries(yourObj).
  2. In ECMAScript 2015, it is possible with Maps.
  3. In ECMAScript 5, it is not possible.

ECMAScript 2017

ECMAScript 2017 introduced a new Object.entries function. You can use this to iterate the object as you wanted.

'use strict';

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

for (const [key, value] of Object.entries(object)) {
  console.log(key, value);
}

Output

a 1
b 2
c 3

ECMAScript 2015

In ECMAScript 2015, there is not Object.entries but you can use Map objects instead and iterate over them with Map.prototype.entries. Quoting the example from that page,

var myMap = new Map();
myMap.set("0", "foo");
myMap.set(1, "bar");
myMap.set({}, "baz");

var mapIter = myMap.entries();

console.log(mapIter.next().value); // ["0", "foo"]
console.log(mapIter.next().value); // [1, "bar"]
console.log(mapIter.next().value); // [Object, "baz"]

Or iterate with for..of, like this

'use strict';

var myMap = new Map();
myMap.set("0", "foo");
myMap.set(1, "bar");
myMap.set({}, "baz");

for (const entry of myMap.entries()) {
  console.log(entry);
}

Output

[ '0', 'foo' ]
[ 1, 'bar' ]
[ {}, 'baz' ]

Or

for (const [key, value] of myMap.entries()) {
  console.log(key, value);
}

Output

0 foo
1 bar
{} baz

ECMAScript 5:

No, it's not possible with objects.

You should either iterate with for..in, or Object.keys, like this

for (var key in dictionary) {
    // check if the property/key is defined in the object itself, not in parent
    if (dictionary.hasOwnProperty(key)) {           
        console.log(key, dictionary[key]);
    }
}

Note: The if condition above is necessary only if you want to iterate over the properties which are the dictionary object's very own. Because for..in will iterate through all the inherited enumerable properties.

Or

Object.keys(dictionary).forEach(function(key) {
    console.log(key, dictionary[key]);
});
Answer from thefourtheye on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Object › entries
Object.entries() - JavaScript - MDN Web Docs
Using array destructuring, you can iterate through objects easily. ... // Using for...of loop const obj = { a: 5, b: 7, c: 9 }; for (const [key, value] of Object.entries(obj)) { console.log(`${key} ${value}`); // "a 5", "b 7", "c 9" } // Using array methods Object.entries(obj).forEach(([key, ...
Top answer
1 of 11
1043

tl;dr

  1. In ECMAScript 2017, just call Object.entries(yourObj).
  2. In ECMAScript 2015, it is possible with Maps.
  3. In ECMAScript 5, it is not possible.

ECMAScript 2017

ECMAScript 2017 introduced a new Object.entries function. You can use this to iterate the object as you wanted.

'use strict';

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

for (const [key, value] of Object.entries(object)) {
  console.log(key, value);
}

Output

a 1
b 2
c 3

ECMAScript 2015

In ECMAScript 2015, there is not Object.entries but you can use Map objects instead and iterate over them with Map.prototype.entries. Quoting the example from that page,

var myMap = new Map();
myMap.set("0", "foo");
myMap.set(1, "bar");
myMap.set({}, "baz");

var mapIter = myMap.entries();

console.log(mapIter.next().value); // ["0", "foo"]
console.log(mapIter.next().value); // [1, "bar"]
console.log(mapIter.next().value); // [Object, "baz"]

Or iterate with for..of, like this

'use strict';

var myMap = new Map();
myMap.set("0", "foo");
myMap.set(1, "bar");
myMap.set({}, "baz");

for (const entry of myMap.entries()) {
  console.log(entry);
}

Output

[ '0', 'foo' ]
[ 1, 'bar' ]
[ {}, 'baz' ]

Or

for (const [key, value] of myMap.entries()) {
  console.log(key, value);
}

Output

0 foo
1 bar
{} baz

ECMAScript 5:

No, it's not possible with objects.

You should either iterate with for..in, or Object.keys, like this

for (var key in dictionary) {
    // check if the property/key is defined in the object itself, not in parent
    if (dictionary.hasOwnProperty(key)) {           
        console.log(key, dictionary[key]);
    }
}

Note: The if condition above is necessary only if you want to iterate over the properties which are the dictionary object's very own. Because for..in will iterate through all the inherited enumerable properties.

Or

Object.keys(dictionary).forEach(function(key) {
    console.log(key, dictionary[key]);
});
2 of 11
159

Try this:

dict = {0:{1:'a'}, 1:{2:'b'}, 2:{3:'c'}}
for (var key in dict){
  console.log( key, dict[key] );
}

0 Object { 1="a"}
1 Object { 2="b"}
2 Object { 3="c"}
Discussions

loops - How to iterate over a JavaScript object? - Stack Overflow
When you iterate over an object there is no guarantee to the order in which they will appear. ... Does this answer your question? How to loop through a plain JavaScript object with the objects as members? ... modern ECMAScript specification: array indices first in ascending order by value, then other string keys ... More on stackoverflow.com
🌐 stackoverflow.com
How to loop through key/value object in Javascript? - Stack Overflow
now I want to create a setUsers() method that takes a key/value pair object and initializes the user variable. More on stackoverflow.com
🌐 stackoverflow.com
Loop through array and create object of specific key/value pairs?
I stuck your whole post in chat GPT, lol: You can use a loop to iterate over the array of objects and create a new object with the required key-value pairs. Here's an example of how you could do it: // input array const slots = [ {"name": "Name1", "task": "Task1"}, {"Value": "Current Value", "temperature": 67, "status": "on"}, {"mode": "Current Mode", "status": "selected"} ]; // output object const slotsObj = {}; // iterate over the input array for (let i = 0; i < slots.length; i++) { const slot = slots[i]; // check if the current object has the required properties if (slot.hasOwnProperty("name")) { slotsObj.name = slot.name; } else if (slot.hasOwnProperty("Value")) { slotsObj.value = slot.Value; } else if (slot.hasOwnProperty("mode")) { slotsObj.mode = slot.mode; } } // create the final object with the required properties const result = { slotsObj }; console.log(result); // output: { slotsObj: { name: 'Name1', value: 'Current Value', mode: 'Current Mode' } } This code checks each object in the slots array for the required properties (name, Value, and mode) and adds them to the slotsObj object. Then it creates the final object with the required structure. Note that if an object doesn't have one of the required properties, it will simply be ignored. More on reddit.com
🌐 r/learnjavascript
6
1
March 31, 2023
How would I access the first key-value pair of the "files" object using a forEach loop?
You can use Object.values() or a similar method, or a for...in loop More on reddit.com
🌐 r/learnjavascript
7
2
November 24, 2022
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Statements › for...in
for...in - JavaScript | MDN - MDN Web Docs
The for...in statement iterates over all enumerable string properties of an object (ignoring properties keyed by symbols), including inherited enumerable properties.
🌐
DEV Community
dev.to › fpaghar › object-iteration-ways-in-javascript-pej
Object Iteration ways in JavaScript - DEV Community
April 8, 2024 - It's a convenient way to iterate over object properties when you're only interested in keys. const obj = { a: 1, b: 2, c: 3 }; Object.keys(obj).forEach(key => { console.log(key + ': ' + obj[key]); }); Remember that Object.keys() ignores inherited ...
🌐
Futurestud.io
futurestud.io › tutorials › iterate-through-an-objects-keys-and-values-in-javascript-or-node-js
Iterate Through an Object’s Keys and Values in JavaScript or Node.js
March 3, 2022 - JavaScript offers different types of loops to iterate through the object. The allrounder is the for…in loop. Since ECMAScript 2015 you can use Object.keys. Starting from ECMAScript 2017 you can use the Object.entries method. This tutorial walks you through each of these loops to iterate through an object’s keys and values.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-iterate-over-a-javascript-object
Iterate over a JavaScript object - GeeksforGeeks
Use map() to access each pair, where index 0 is the key and index 1 is the value. ... function iterateObject() { let exampleObj = { book: "Sherlock Holmes", author: "Arthur Conan Doyle", genre: "Mystery" }; Object.entries(exampleObj).map(entry ...
Published   October 14, 2025
Top answer
1 of 16
1341

For iterating on keys of Arrays, Strings, or Objects, use for .. in :

for (let key in yourobject) {
  console.log(key, yourobject[key]);
}

With ES6, if you need both keys and values simultaneously, do

for (let [key, value] of Object.entries(yourobject)) {
    console.log(key, value);
}

To avoid logging inherited properties, check with hasOwnProperty :

for (let key in yourobject) {
   if (yourobject.hasOwnProperty(key)) {
      console.log(key, yourobject[key]);
   }
}

You don't need to check hasOwnProperty when iterating on keys if you're using a simple object (for example one you made yourself with {}).

This MDN documentation explains more generally how to deal with objects and their properties.

If you want to do it "in chunks", the best is to extract the keys in an array. As the order isn't guaranteed, this is the proper way. In modern browsers, you can use

let keys = Object.keys(yourobject);

To be more compatible, you'd better do this :

 let keys = [];
 for (let key in yourobject) {      
     if (yourobject.hasOwnProperty(key)) keys.push(key);
 }

Then you can iterate on your properties by index: yourobject[keys[i]] :

for (let i=300; i < keys.length && i < 600; i++) { 
   console.log(keys[i], yourobject[keys[i]]);
}
2 of 16
101

Here is another iteration solution for modern browsers:

Object.keys(obj)
  .filter((k, i) => i >= 100 && i < 300)
  .forEach(k => console.log(obj[k]));

Or without the filter function:

Object.keys(obj).forEach((k, i) => {
    if (i >= 100 && i < 300) {
        console.log(obj[k]);
    }
});

However you must consider that properties in JavaScript object are not sorted, i.e. have no order.

Find elsewhere
🌐
Latenode
latenode.com › home › blog › development & programming › javascript for automation › how to iterate over a javascript object?
How to Iterate Over a JavaScript Object? - Latenode Blog
February 12, 2026 - The Object.entries() method provides a convenient way to get an array of key-value pairs from an object. By combining it with the map() method, you can easily iterate over the array and perform operations on each key-value pair.
🌐
Coderwall
coderwall.com › p › _kakfa › javascript-iterate-through-object-keys-and-values
JavaScript iterate through object keys and values (Example)
June 26, 2023 - I just wanted to keep this for reference how to quickly loop through an objects keys and values, if needed. I also included an implementation using jQuery .each · Note the limitations of using a for...in loop, as it iterates over the properties of an object in an arbitrary order, and needs to use .hasOwnProperty, unless inherited properties want to be shown.
🌐
Attacomsian
attacomsian.com › blog › javascript-iterate-objects
How to iterate over object keys and values in JavaScript
November 12, 2022 - To iterate over the nested array returned by Object.entries(), use the for...of loop or the forEach() method as shown below: // => `for...of` Loop for (const [key, value] of Object.entries(birds)) { console.log(`${key} -> ${value}`) } // => ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Object › keys
Object.keys() - JavaScript - MDN Web Docs
If you need both the property keys and values, use Object.entries() instead. ... // 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']
🌐
Flexiple
flexiple.com › javascript › loop-through-object-javascript
How to loop through objects keys and values in Javascript?
For more specific tasks, Object.keys(), Object.values(), and Object.entries() methods can be utilized, offering arrays of keys, values, or [key, value] pairs, respectively. These arrays can then be looped over using array iteration methods like ...
🌐
Medium
sunnygandhi01.medium.com › how-to-iterate-through-an-object-keys-and-values-in-javascript-d8bb464615fa
How to Iterate through an object keys and values in JavaScript. | by Sunnygandhi | Medium
January 13, 2021 - const fruits : { Mango: 100, Apple: 10, Orange: 50, Kiwi: 5 };const entries = Object.entries(fruits); console.log(entries);Output: ['Mango', '100']; ['Apple', '10']; ['Orange', '50']; ['Kiwi', '5'];//To iterate over the array return we can use for..each method. Object.entries(fruits).forEach(function(key, index) { console.log(`${key}: ${value}`) };Output: Mango: 100 Apple: 10 Orange: 50 Kiwi: 5 ... That’s all for iterating over object properties in JavaScript.
🌐
Envato Tuts+
code.tutsplus.com › home › coding fundamentals
How to Iterate Over Object Keys With JavaScript | Envato Tuts+
May 20, 2022 - This method iterates over all of the object's enumerable, non-symbol properties. In the following example, we use it to iterate over all three properties of obj, and for each property, we log a string consisting of the property name (i.e. its key) and its corresponding value.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › foreach-object
Iterating Through an Object with `forEach()` - Mastering JS
May 29, 2020 - You can then iterate over each key in the object using forEach(). const obj = { name: 'Jean-Luc Picard', rank: 'Captain' }; // Prints "name Jean-Luc Picard" followed by "rank Captain" Object.keys(obj).forEach(key => { console.log(key, obj[key]); ...
🌐
Hostman
hostman.com › tutorials › looping through objects’s keys and values in javascript
How to loop through objects keys and values in Javascript? | Hostman
August 25, 2025 - By understanding the syntax and usage of the feature, you can improve the functionality of working with objects and shorten your code. The built-in Object.keys() method in JavaScript allows you to get an array of all the keys of a given object.
Price   $
Address   1999 Harrison St 1800 9079, 94612, Oakland
🌐
Esdiscuss
esdiscuss.org › topic › es6-iteration-over-object-values
ES6 iteration over object values
September 28, 2014 - Le 15/03/2014 01:32, Brandon Benvie a écrit : > On 3/14/2014 5:16 PM, Mark Volkmann wrote: >> Does ES6 add any new ways to iterate over the values in an object? >> I've done a lot of searching, but haven't seen anything. >> I'm wondering if there is something more elegant than this: >> >> Object.keys(myObj).forEach(function (key) { >> let obj = myObj[key]; >> // do something with obj >> }); > > Not built in, but ES6 does provide a better story for this using > generators and for-of: > > ```js > // using a generator function > function* entries(obj) { > for (let key of Object.keys(obj)) { > yi
🌐
freeCodeCamp
freecodecamp.org › news › how-to-iterate-over-objects-in-javascript
Loop Through an Object in JavaScript – How to Iterate Over an Object in JS
November 7, 2024 - const population = { male: 4, female: 93, others: 10 }; // Iterate through the object for (const key in population) { if (population.hasOwnProperty(key)) { console.log(`${key}: ${population[key]}`); } } To avoid the stress and difficulty of looping and to use the hasOwnProperty method, ES6 and ES8 introduced object static methods. These convert object properties to arrays, allowing us to use array methods directly. An object is made up of properties that have key-value pairs, that is each property always has a corresponding value.
🌐
Effective TypeScript
effectivetypescript.com › 2020 › 05 › 26 › iterate-objects
Effective TypeScript › Item 54: Know How to Iterate Over Objects
May 26, 2020 - Hopefully this doesn't happen in ... If you want to iterate over the keys and values in an object, use either a keyof declaration (let k: keyof T) or Object.entries....