0

I have this code in Javascript:

const arrayPilots = [0];

const addToStorage = () => {
    arrayPilots.push(1);

    console.log(arrayPilots);
};

Which happens that when I run it with the following html:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="style.css"/>
        <script src="./script-copia.js"></script>
        <title>CRUD Pilotos</title>
    </head>
    <body>
        <div class = "flexboxCenter">
            <div class="flexboxLeft">
                <h1>CRUD pilotos</h1>
                <form>
                    <div class = "flexboxForm">
                        <label>Id: </label>
                        <input type="number" id="id">
                        <span id = "error"></span>
        
                        <label>Name: </label>
                        <input type="text" id="name">
        
                        <label>Years: </label>
                        <input type="number" id="years">
                            <!--TODO: Añadir Campo después del Id pasado por parámetro -->
                        <div class="input-submit">
                            <input type="submit" value="Añadir" id="addPilot" onclick="addToStorage()">
                            <input type="submit" value="Modificar" id="modifyPilot">
                            <input type="submit" value="Eliminar" id="deletePilot">
                        </div>
                        
                    </div>
                </form>
            </div>
            <div id="tableDiv" class="flexboxRight">
                <!-- <table>
                    <thead>
                        <tr>
                            <th>Resultado</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Hola</td>
                        </tr>
                        <tr>
                            <td>Mundo</td>
                        </tr>
                    </tbody>
                </table> -->
            </div>
        </div>
    </body>
</html>

The array adds the value to its collection, but then after the variable keeps the same value as the original, some beautiful soul master in Javascript that could help me? This is the output in the function after pushing it: enter image description here

And after all executes in the debug console:

enter image description here

Thanks in advance.

I tried when you click the button on the html, its added to the list the number '1', to check if the value stays there or it hasn't 'saved the changes'.

J.J. S.G.
  • 1
  • 1

0 Answers0