Last updated 2 years ago
JS ⟩ objects ⟩ Array ⟩ methods ⟩ entries()
Object.entries() - keys are string-based.
Array.prototype.entries() - keys are integer-based.
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' ❗❗❗ }
arr.rank() - rank an array of objects.
for-of