Does Object.keys traverse objects?

Object.keys(obj).forEach(item => {
    console.log(obj[item])
})

is this equivalent to traversing twice, and will it have an impact on performance?

Mar.09,2021

is traversed twice. But I don't understand the intention of your code. The time complexity is that the O (n)
Object.keys () method returns an array of enumerable attributes of a given object
forEach () method to execute the provided function once for each element of the array.
your code

Object.keys(obj).forEach(item => {
    console.log(obj[item])
})
The

Object.keys (obj) traversal returns the key array of obj, but the forEach outputs the value value

of obj .

maybe you want to traverse the key value of the output object

var obj = {
    '0': 'a',
    '1': 'b',
    '2': 'c'
}
console.log(...(Object.keys(obj))) 
// 0 1 2

according to polyfill , it has to be traversed twice. However, if the order of magnitude is very small and the number of calls is not frequent, there is not much impact on performance


your code just for in once traversing.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3708b-2b8aa.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3708b-2b8aa.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?