Search notes:

JavaScript statements: for (x in obj) { … }

The for (x in obj) { … } statement allows to iterate over elements in objects such as arrays or associative arrays.
for (obj of objs) { … }
#!/usr/bin/env js52

//
// Iterating over array
//
var a = ['foo', 'bar', 'baz']
for (i in a) {
  print(i);
  // 0
  // 1
  // 2
}
for (j in a) {
  print(a[j])
  // foo
  // bar
  // baz
}

//
// Iterating over keys in an associative array (hash / dict):
//
var d = {x: 'eggs', y: 'why'}

for (k in d) {
  print('d[' + k + '] = ' + d[k])
  // d[x] = eggs
  // d[y] = why
}
Github repository about-javascript, path: /statements/for/in.js

See also

for
Javacript statements
The forEach() method of the Array object.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758193863, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/JavaScript/language/statements/for/in(78): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78