Object.keys(obj).forEach(item => {
console.log(obj[item])
})
is this equivalent to traversing twice, and will it have an impact on performance?
Object.keys(obj).forEach(item => {
console.log(obj[item])
})
is this equivalent to traversing twice, and will it have an impact on performance?
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
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.
function f2() { try { Promise.reject( ); } catch(e) { console.log(e) } } execute f2 () , and Uncaught (in promise) cannot be thrown from the promise.reject, console captured by try catch. async function f() { try { await Pr...
such as the title. If you implement ES6 built-in feature Set, without using other es6 API (such as Map) if you want to write a Set that class imitates, should the underlying data structure use array or Object? ...
I have a txt file there are 10,000 lines the first line is as follows 27466726----6837605--------398705040011----7605----60664----qq what I want to extract is 27466726 6837605 398705040011 7605 60664 qq the second line is as follows zaistarm---...