TypeScript Array entries() Method Last Updated : 19 Jul, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The Array.prototype.entries() method in TypeScript returns a new array iterator object that contains the key/value pairs for each index in the array. This method is useful when you need to iterate over the key/value pairs in the array.Note: In TypeScript, the entries() method is not available directly on arrays as it is in JavaScript for objects, but we can achieve a similar result through a different approach. Syntax:Object.entries(arrayName)Return Value:An iterator that yields key-value pairs, where keys are indices and values are array elements.Examples of Array entries() MethodExample 1: Accessing Student Names and Indices Using entries()In this example, we will use the entries() method to iterate over the student names array and access their indices and values. JavaScript const students: string[] = ["Pankaj", "Ram", "Shravan"]; const iterator = students.entries(); for (let entry of iterator) { const [index, value] = entry; console.log(`Index: ${index}, Value: ${value}`); } Output:Index: 0, Value: Pankaj Index: 1, Value: Ram Index: 2, Value: ShravanExample 2: Accessing Number Array Elements with Indices Using a While LoopIn this example, we will use the entries() method and a while loop to iterate over a number array and access their indices and values. JavaScript const numbers: number[] = [10, 20, 30]; const iterator = numbers.entries(); let result = iterator.next(); while (!result.done) { const [index, value] = result.value; console.log(`Index: ${index}, Value: ${value}`); result = iterator.next(); } Output:Index: 0, Value: 10 Index: 1, Value: 20 Index: 2, Value: 30Supported Browsers:Google ChromeEdgeFirefoxOperaSafari Comment More infoAdvertise with us Next Article C# | Implicitly Typed Arrays P pankajbind Follow Improve Article Tags : TypeScript javaScript Similar Reads TypeScript Array Object.entries() Method The Object.entries() method in TypeScript is used for creating an array of key-value pairs from an object's keys and values. This method simplifies the process of iterating over an object's properties and enables easier data manipulation.SyntaxObject.entries(obj);Parameterobj: It takes the object as 3 min read TypeScript Arrays An array is a user-defined data type. An array is a homogeneous collection of similar types of elements that have a contiguous memory location and which can store multiple values of different data types.An array is a type of data structure that stores the elements of a similar data type and consider 5 min read TypeScript Object The Array Type In TypeScript, the Array Type is used to specify and enforce the type of elements that can be stored in an array, enhancing type safety during development. This adaptability ensures reusability across diverse data types, as exemplified by the Array type (e.g., number[] or string[]). Syntaxlet myArra 2 min read Solidity - Arrays Arrays are data structures that store the fixed collection of elements of the same data types in which each and every element has a specific location called index. Instead of creating numerous individual variables of the same type, we just declare one array of the required size and store the element 6 min read C# | Implicitly Typed Arrays Implicitly typed arrays are those arrays in which the type of the array is deduced from the element specified in the array initializer. The implicitly typed arrays are similar to implicitly typed variable. In general, implicitly typed arrays are used in the query expression.Important points about im 3 min read One Dimensional Array in Java An array is a type of data structure that can store a collection of elements. These elements are stored in contiguous memory locations and provide efficient access to each element based on the index of each array element.In this article, we will learn about a one-dimensional array in Java.What is an 7 min read Like