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

  • Home
  • SEARCH
  • 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 8498591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:26:42+00:00 2026-06-11T00:26:42+00:00

When I do this: var testArray = [a,b,c]; console.log(testArray); console.log(size: + testArray.length); I this

  • 0

When I do this:

var testArray  = ["a","b","c"];
console.log(testArray);
console.log("size:" + testArray.length);

I this this printed in my console:

["a", "b", "c"]
size:3 

Which is good. But now when I start splicing with this:

var testArray  = ["a","b","c"];
console.log(testArray);
console.log("size:" + testArray.length);
testArray = testArray.splice(0,1);

This happens to show in my console:

["b", "c", undefined × 1]
size:3 

So first question is why does it mess up my printing of the array even though the splice was after the printing? The size is shown correctly but the “a” is gone and I get an undefined at the end.

So what I wanted to do was to remove the first item in the array. Basically a shift. So I do this:

var testArray  = ["a","b","c"];
console.log(testArray);
console.log("size:" + testArray.length);
testArray = testArray.splice(0,1);
console.log(testArray);
console.log("size:" + testArray.length);

And this is what gets outputted:

["b", "c", undefined × 1]
size:3
["a"]
size:1 

Not only did the size decrease by 2, it deleted everything but the “a”. What is going on?

  • 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-11T00:26:44+00:00Added an answer on June 11, 2026 at 12:26 am

    Dont assign testArray to itself. Simply do:

    var testArray  = ["a","b","c"];
    console.log(testArray);
    console.log("size:" + testArray.length);
    testArray.splice(0,1);
    console.log(testArray);
    console.log("size:" + testArray.length);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this: var blockRegEx = new Regex((proc sql;)(.*?)(quit;), RegexOptions.IgnoreCase | RegexOptions.Multiline); but it
I'm trying at this: var cur_border = $('id_grid_pic_'+cur_id).attr('border'); alert(cur_border); But the alert sends back
Sure, even I can do this... var testarray : array of string; setlength(testarray, 5);
I have a sparse array (indexes are not consecutive) like this: var testArray =
I am currently doing this but it isn't working: var tempArray=new Array(); var number
I have this: var testArray = []; testArray[First] = First Test Data; testArray[Second] =
Array.prototype.move = function(oldIndex, newIndex) { var val = this.splice(oldIndex, 1); this.splice(newIndex, 0, val[0]); }
Having an object like this: var a = { b: string, c: function(){ return
I have code like this var MyObj = { f1 : function(o){ o.onmousedown =
I have this var n = ItemList.Select(s => new { s.Vchr, s.Id, s.Ctr, s.Vendor,

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.