数组迭代器方法拆分键值对的小Tip

数组迭代器方法拆分键值对的小Tip

使用 ES6 的解构可以非常容易地在循环中拆分键/值对


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!

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_45416217/article/details/113915796