📘arr.entries

JSobjectsArraymethods ⟩ entries()

💾 replit: arr.entries() vs Object.entries(arr)

const a = ['a', 'b', 'c'];
    
// ⭐️ keys are "integers"
Array.from(a.entries()),    // [ [ 0, 'a' ], [ 1, 'b' ], [ 2, 'c' ] ]

// ⭐️ keys are "strings"
Object.entries(a),          // [ [ '0', 'a' ], [ '1', 'b' ], [ '2', 'c' ] ]

for(const [i, value] of Object.entries(a)) {
    console.log(i + 1);     // 🧨 雷區:'01', '11', '21' ❗❗❗ 
}

Last updated