JavaScript Array entries() MethodThe entries() method creates a new iterator object of an array, holding the key/value pairs for every value in the array. A key represents the index number carrying an item as its value. It does not affect the original array. SyntaxThe following syntax represents the entries() method: ParametersIt does not have any parameters. ReturnIt returns the newly created array iterator object. The iterator object represents each element of the array with keys assigned to them. JavaScript Array entries() Method ExamplesLet's implement some examples to understand the toString() method better: Example1: A simple array entries() method an array. Test it NowOutput: The output shows the elements of the array with key assigned to it. Thus, together forms a key/value pair. Example2: This example represents the array entries() method through let declaration. Test it NowOutput: The output will be same as shown in the above example. Example3: This example displays the (key,value) pairs of the array by clicking on the "apply" button. Test it NowOutput: After calling the arr() function, the output comes out: Example4: Displaying the position of the candidates in the given array. Test it NowOutput: The output will be: Example5: Test it NowOutput: After clicking on the "display" button, the position of each number in the array will be:
Next TopicJavaScript Array
|