Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
20 lines (18 loc) · 535 Bytes

File metadata and controls

20 lines (18 loc) · 535 Bytes
Copy raw file
Download raw file
Edit and raw actions

Enumeration

The for in statement can loop over all of the property names in an object. The enumeration will include functions and prototype properties.

var fruit = {
    apple: 2,
    orange: 5,
    pear: 1,
  },
  sentence = "I have ",
  quantity;
for (kind in fruit) {
  quantity = fruit[kind];
  sentence += quantity + " " + kind + (quantity === 1 ? "" : "s") + ", ";
}
// The following line removes the trailing coma.
sentence = sentence.substr(0, sentence.length - 2) + ".";
// I have 2 apples, 5 oranges, 1 pear.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.