Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!