JavaScript(JS) JS loop through an object

To loop through an object in JavaScript/JS, you can use a for...in loop. Here's an example:

refer to‮‬:theitroad.com
const myObj = {a: 1, b: 2, c: 3};

for (let key in myObj) {
  console.log(key + ": " + myObj[key]);
}

In this example, the for...in loop iterates over each key in the myObj object and logs the key and its corresponding value to the console.

Note that when iterating over an object with for...in, the keys are always strings, even if they look like numbers. If you need to perform mathematical operations on them, you'll need to convert them to numbers using parseInt() or parseFloat().