Solucionado (ver solución)
Solucionado
(ver solución)
2
respuestas

4.7_Superman quedó fuera por un pelo

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <script>
        var heroes = ["Superman", "Thor", "Batman", "Mujer Maravilla"];
        for (var i = 0; i < heroes.length; i++) { /*The first element into an array in JavaScript like in the most programming computer languages is the one with the index 0 not the one with index 1.*/
            alert(heroes[i]);
        }
    </script>

</body>

</html>
2 respuestas
solución!

¿Cuál es el problema con el código de Felipe? Felipe was suppousing that the index 1 in the array was the first element of the array, but Felipe was wrong, the index of the first element in an array is the index 0 not the index 1, the cardinality of the elements into an array is offset by one with respect to it index, being the index 0 the one which represent the first element of the array.

¿Cómo puede cambiarlo para que muestre todos los nombres en la lista sin omitir ninguno? The solution to Felipe´s problem is relatively easy. Felipe just have to change the initial value of the local variable "i" in the for loop from 1 to 0. In such a manner the first element to show in the "alert" function in fact will be the first element of the array not the second as it used to be.

El error esta en la inicialización de la variable del lazo For (i) que si bien el lazo recorre hasta el final del array ya que toma como numero limite superior la long del mismo, comienza a recorrerlo en el segundo elemento ya que i esta inicializada en 1 y los arrays inician con un indice 0