Js traverses objects in the form of key value pairs or methods in the form of Map

  • 2021-07-09 07:01:31
  • OfStack

Recent use of ajax in the project returned an map object. How do you iterate through this map object? I checked a lot on the Internet, but it was really useful. Finally, it reminded me of an object that needed to traverse key=Value before. After thinking about this way, it should also be applicable to map. So I tried it and it worked! Record it for later use.

How to traverse key=value key-value pairs, object data in JS (it can also be in the form of map).


for ( var key in changes) {			
// Through the method of traversing object attributes, traversing key-value pairs, and obtaining key , and then through   Object [key] Get the corresponding value 			
name = key;			
value = changes[key];} 

Related articles: