JSFiddle - React, Tailwind, and code Playground

by Rufuus06

HTML

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

  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Unshift()</title>
  </head>
  
  <body>
    
    <h2>Unshift():</h2>
    <p>Añade un elemento a la primera posición de un array y mueve el resto una posición más.</p>
  
    <p id="exp"></p>
    <p id="exp2"></p>
    
  </body>
  
</html>

JavaScript

var frutas = ["Platano", "Naranja", "Manzana", "Mango"];
document.getElementById("exp").innerHTML = frutas.join(", ") + " [" + frutas.length + "]";

frutas.unshift("Limon");
document.getElementById("exp2").innerHTML = frutas.join(", ") + " [" + frutas.length + "]";