- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the use of Array.entries() method in JavaScript?
Array.entries()
The Array.entries() in JavaScript is used to get a new Array that contains the key and value pairs for each index of an array. It returns an Array Iterator object with key/value pairs.
syntax
array.entries();
Example
In the following example elements.entries() method, using for loop, access every element and generate key/value pair of the particular element.To simplify the code we just assigned an iterator variable to elements.entries().
<html> <body> <script> var elements = ["Helium", "Neon", "Krypton", "Xenon", "Radon"]; var iterator = elements.entries(); for (let e of iterator) { document.write(e); document.write("</br>"); } </script> </body> </html>
Output
0,Helium 1,Neon 2,Krypton 3,Xenon 4,Radon
Advertisements