close

How to iterate (keys, values) in JavaScript?

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How to iterate (keys, values) in JavaScript? in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How to iterate (keys, values) in JavaScript ?

  1. How to iterate (keys, values) in JavaScript ?

    to iterate (keys, values) in JavaScript You can use JavaScript forEach Loop:
    myMap.forEach((value, key) => { console.log('value: ', value); console.log('key: ', key); });

  2. How to iterate (keys, values) in JavaScript ?

    to iterate (keys, values) in JavaScript You can use JavaScript forEach Loop:
    myMap.forEach((value, key) => { console.log('value: ', value); console.log('key: ', key); });

Method 1

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"}

Method 2

You can use JavaScript forEach Loop:

myMap.forEach((value, key) => {
    console.log('value: ', value);
    console.log('key: ', key);
});

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment