0
what is next() method?
<script> var fruits = ["Banana", "Orange", "Apple", "Mango"]; var x = fruits.keys(); document.getElementById("demo").innerHTML = x.next().value; //output 0 </script>
1 Respuesta
+ 3
Array.prototype.keys()
returns a new Array Iterator object that contains the keys for each index in the array.
And indexes are 0, 1, 2, 3
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys
Generator.prototype.next()
returns an object with two properties done and value.
without argument yields first object { value : 0, done : false}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next
so, fruits.keys().next().value is 0