Name

for/in — NN 2 IE J1 ECMA 1

Synopsis

A variation of the regular for loop that can extract the property names and values of an object.

Syntax

for (varName in objectRef) {
    statements
}

Example

function showProps() {
    objName = "image"
    obj = document.images[0]
    var msg = ""
    for (var i in obj) {
        msg += objName + "." + i + "=" + obj[i] + "\n"
    }
    alert(msg)
}

Get Dynamic HTML: The Definitive Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.