Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

191
Visualizações
How to change the value of the index number of an array so that it would start from 1 instead of 0

How do i make it so that the index starts with 1 instead of 0. Also how would i make it 1st, 2ed, 3rd etc. in instead on 1 2 3 etc.

<p id = "array"></p>        
    <script>
            var car = ["Nissan Skyline R34 GTR", "Toyota Supra A80", "Mazda RX7 FD3S", "Honda NSX Type R", "Nissan 240SX", "Toyoto AE86", "Subaru Impreza WRX Sti", "Honda Civic EG6"];
            
            var text = "";
            car.forEach(script)
            document.getElementById("array").innerHTML = text;
            
            function script (value, index, array) {
              text += ("My #" + index + " choice is " + value + ". <br>");
            }
        </script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

How to change the value of the index number of an array so that it would start from 1 instead of 0

Just answering the question without asking why you want that: You can achieve it by inserting and deleting a dummy element 0.

<p id = "array"></p>        
<script>
    var car = ["", "Nissan Skyline R34 GTR", "Toyota Supra A80", "Mazda RX7 FD3S", "Honda NSX Type R", "Nissan 240SX", "Toyoto AE86", "Subaru Impreza WRX Sti", "Honda Civic EG6"];
    delete car[0]
    var text = "";
    car.forEach(script)
        document.getElementById("array").innerHTML = text;

    function script(value, index, array)
    { text += ("My #" + index + " choice is " + value + ". <br>"); }
</script>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda