Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9128887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:37:17+00:00 2026-06-17T07:37:17+00:00

I am attempting to populate array: var array2 = [a, b, c]; With some

  • 0

I am attempting to populate array:

var array2 = ["a", "b", "c"];

With some random number/value, so that the value separates each original value.
However, using a for loop like this:

for (var am = 1; am < array2.length; am+2) {
   array2.splice(am, 0, undefined);
}

Causes my browser to freeze, since on each splice the array2’s length mutates and causes an infinite loop so I attempted this method:

var l = array2.length;

for(var i = 1; i < l; i+2) {
   array2.splice(i, 0, undefined);
}

Now I don’t know what’s going on. I assume l is mutating again.

I have to advance i for two because array2 after the first splice becomes:

["a", undefined, "b", "c"];

However, since i = 3 and I’ve set the expression i < l, the only explanation is that l is changing again.

Any explanation would be welcome. The end result of how I want the code to proceed is:

array2 = ["a", undefined, "b", undefined, "c"];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:37:19+00:00Added an answer on June 17, 2026 at 7:37 am
    for (var am = 1; am < array2.length; am+2) {
    

    You’re not actually incrementing am in that line. Change it to:

    for (var am = 1; am < array2.length; am+=2) {
    

    Using += means am = am + 2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm attempting to populate an array with random numbers, but the random numbers must
I'm attempting to populate a select field with options using bootstrapped data. I'm encountering
I am attempting to use a remote service to populate an autocomplete field that
I am attempting to populate a ScrollerViewer control with an arbitrary number of of
I'm attempting to populate a DB on my local SQL2008 Server using a Data
I am attempting to populate a dropdown based on the value selected in another
I'm using this android calendar http://w2davids.wordpress.com/android-simple-calendar/ and attempting to populate it with events. In
I am attempting to populate a form field prior to it being submitted however
Currently attempting to save an array that is populated according to which cells in
I have some code that takes an array of url's and I have one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.