Array iterator method to split small tips of key-value pairs

Array iterator method to split small tips of key-value pairs

Destructuring using ES6 makes it very easy to split key/value pairs in a loop


const a = ["foo", "bar", "baz", "qux"]; 
for (const [idx, element] of a.entries()) {
    
     
 alert(idx); 
 alert(element); 
} 
// 0 
// foo 
// 1 
// bar 
// 2 
// baz 
// 3 
// qux
真是niceeeeeeeeeeeeee!

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_45416217/article/details/113915796