In ESLint mode, for in will report an error when traversing the object, which can be solved as follows:
let val = { shu: [ 1 , 2 , 3 ]} ;
for (let item in val) {
if (val.hasOwnProperty(item)) {
console.log(item);
}
}
Because we should judge whether the object has its own properties (non-inheritance) before traversing an object. If the object is an empty object, then there is no need to traverse it to improve the efficiency of the code.