DEV Community

VICTOR OMONDI
VICTOR OMONDI

Posted on

Object looping in Python vs Javascript

Python

obj = {
    'name': 'Victor'
}

for key in obj:
    print("key: %s, value: %s" % (key, obj[key]))
Enter fullscreen mode Exit fullscreen mode

Javascript:

let obj = {
    name: 'Victor'
}

for (key in obj) {
    console.log(`Key: ${key}, value: ${obj[key]}`);
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)