JavaScript loop / foreach an object

Coming from PHP I wondered how do to a simple foreach() in JavaScript.

function loopObject($object) {
    for (const [$key, $value] of Object.entries($object)) {
        // dome something
    }
}

Not that once I found the entries function. Why I use the dollar sign $ for the variables? It is a habit and easier to read and it avoids conflicts with language reserved words.

Leave a Reply

Your email address will not be published. Required fields are marked *