rashmi agar
8 posts
Mar 07, 2025
9:12 PM
|
javascript array entries is a built-in method that returns an iterator object with key-value pairs representing array indexes and their corresponding values. This is particularly useful when looping through arrays.
Example: javascript Copy Edit const fruits = ["apple", "banana", "cherry"]; const iterator = fruits.entries();
for (let entry of iterator) { console.log(entry); } // Output: // [0, "apple"] // [1, "banana"] // [2, "cherry"] Benefits of Using entries() Allows iteration with both index and value. Compatible with for...of loops for cleaner code. Helps in managing key-value relationships within arrays
|