Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How to loop through an object in JavaScript with a for…in loop

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]}`);
  }
}
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #How #loop #object #JavaScript #loop
ADD COMMENT
Topic
Name
8+8 =