Tableau : la méthode push

posted in: javascript | 0

La méthode push ajoute un nouvel élément dans un tableau.

Le code expliqué

<p>La méthode push ajoute un nouvel élément dans un tableau.</p>
<button onclick= »myFunction() »>Essayez !</button>
<p id= »demo »></p>
<script>
var cours = [« Français », « Histoire », « Géographie », « Sciences »];
document.getElementById(« demo »).innerHTML = cours;
function myFunction() {
cours.push(« Mathématiques »)
document.getElementById(« demo »).innerHTML = cours;
}
</script>

logowebmaster1