what is next() method? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren

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>

11th Jan 2019, 3:32 PM
Sleeping Fox
Sleeping Fox - avatar
1 Antwort
+ 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
11th Jan 2019, 4:06 PM
Gordon - avatar