JavaScript/Reserved words/in

From Wikibooks, open books for an open world
Jump to navigation Jump to search
Previous: import Reserved words Next: instanceof

The in keyword[edit | edit source]

The in keyword is used for a shorter notation of the for loop.

Examples[edit | edit source]

The code
  var numbers = [2, 3, 5, 7, 10, 11], result = 1;

  for (number in numbers) {
    result += number;
    console.log("result = " + result);

    if (result%2 == 0) {
      continue;
    }

    if (result > 20) {
      break;
    }
  }
returns the following:
result = 3
result = 6
result = 11
result = 18
result = 28
result = 39


See also[edit | edit source]

Previous: import Reserved words Next: instanceof