vendredi 6 novembre 2020

Mistake in javascrpit with NaN result in alert loop [closed]

When I execute this piece of code in javascript, the alert shows for the index of 23, but the for and if loop only return NaN as the 5 numbers that are greater than 5.

       var array = [2, 4, 2, 4, 2.3, 1, 4, 23, 43, 32, 33, 12]
        alert(array.indexOf(23));
        for (var i = 0; i < array.length; i++) {
            console.log(array[i]);
            if (array[i] > 10) {
                alert(parseInt(array.value));
            }
        }

Aucun commentaire:

Enregistrer un commentaire