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>Splice()</title>
  </head>
  
  <body>
    
    <h2>Splice():</h2>
    <p>
      Añade un elemento a un array en la posición que indica el primer Int, y el segundo Int indica los elementos que hay que eliminar después del nuevo.
    </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.splice(2, 2, "Limon", "Kiwi");
document.getElementById("exp2").innerHTML = frutas.join(", ") + " [" + frutas.length + "]";