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 6013793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:36:00+00:00 2026-05-23T02:36:00+00:00

I want to remove an item from an array, is array.splice(x,1) the best way

  • 0

I want to remove an item from an array, is array.splice(x,1) the best way to go?

Is array.splice(x,1) functionally equivalent to delete array[x]; array.length-=1 ?

I’ve read these threads: Javascript object with array, deleting does it actually remove the item? and Deleting array elements in JavaScript – delete vs splice

and did some tests:

<script>
var arr=[];
for(var x=0;x<100000;++x){
    arr.push(x);
}
var a=new Date().getTime();
for(var x=0;x<50000;++x){
    arr.splice(49999,1);
}
var b=new Date().getTime();
alert(b-a);
</script>

<script>
var arr=[];
for(var x=0;x<100000;++x){
    arr.push(x);
}
var a=new Date().getTime();
for(var x=0;x<50000;++x){
    delete arr[49999];
    arr.length-=1;
}
var b=new Date().getTime();
alert(b-a);
</script>

The timing difference is over a magnitude of 100, making the itch to use the second solution almost irresistable.. but before using it, I would like to ask this question: are there any traps i should look out for when i use delete array[x]; array.length-=1 instead of array.splice(x,1)?

  • 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-05-23T02:36:01+00:00Added an answer on May 23, 2026 at 2:36 am

    If you’re just lopping off the last element in the array, you can use pop() and throw away the result or just decrement the length by 1. The delete operator isn’t even required here, and splice() is more appropriate for other uses.

    Specifically, section 15.4 of the ECMAScript specification says:

    whenever the length property is changed, every property whose name is an array index whose value is not smaller than the new length is automatically deleted.

    Both methods mentioned are outlined at MDC:

    • Array pop()
    • Array length

    Either are appropriate for your situation – by all means modify length if you get better performance from it.

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

Sidebar

Related Questions

I want remove "Language" querystring from my url. How can I do this? (using
I want to remove a UIView from a superview and add it again at
I'm using subversion (TortoiseSVN) and I want to remove the .svn folders from my
I have a bunch of java files from which I want to remove the
I have an ArrayList<String> , and I want to remove repeated strings from it.
I want to use the Publish.GacRemove function to remove an assembly from GAC. However,
I have an datetime object that I want to remove one hour to display
Imagine I have String in C#: I Don’t see ya.. I want to remove
have downloaded Orca to edit an MSI file. I want to remove some banner
im building a new side with movable type. And i want to remove the

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.