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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:48:15+00:00 2026-05-23T10:48:15+00:00

Possible Duplicates: How can I unset a JavaScript variable? How do I remove a

  • 0

Possible Duplicates:
How can I unset a JavaScript variable?
How do I remove a property from a JavaScript object?

I’m looking for a way to remove/unset the properties of a JavaScript object, so they’ll no longer come up if I loop through the object doing for (var i in myObject). How can this be done?

  • 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-23T10:48:15+00:00Added an answer on May 23, 2026 at 10:48 am

    Simply use delete, but be aware that you should read fully what the effects are of using this:

     delete object.index; //true
     object.index; //undefined
    

    But if I was to use like so:

    var x = 1; //1
    delete x; //false
    x; //1
    

    But if you do wish to delete variables in the global namespace, you can use its global object such as window, or using this in the outermost scope, i.e.,

    var a = 'b';
    delete a; //false
    delete window.a; //true
    delete this.a; //true
    

    Understanding delete

    Another fact is that using delete on an array will not remove the index, but only set the value to undefined, meaning in certain control structures such as for loops, you will still iterate over that entity. When it comes to arrays you should use splice which is a prototype of the array object.

    Example Array:

    var myCars = new Array();
    myCars[0] = "Saab";
    myCars[1] = "Volvo";
    myCars[2] = "BMW";
    

    If I was to do:

    delete myCars[1];
    

    the resulting array would be:

    ["Saab", undefined, "BMW"]
    

    But using splice like

    myCars.splice(1,1);
    

    would result in:

    ["Saab", "BMW"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can Read-Only Properties be Implemented in Pure JavaScript? I have an Object
Possible Duplicates: JavaScript: Getting random value from an array How can I choose an
Possible Duplicates: Check if Ruby object is a Boolean How can I avoid truthiness
Possible Duplicates: Remove duplicates in large MySql table Can I extract the extract records
Possible Duplicates: Good way to convert between short and bytes? How can I combine
Possible Duplicates: How to check if an object is nullable? Determine if reflected property
Possible Duplicates: Can you write object oriented code in C? Object Oriented pattern in
Possible Duplicates: How can I get the size of an array from a pointer
Possible Duplicates: JavaScript query string get querystring with jQuery Is there an object/method in
Possible Duplicates: How do you check if a variable is an array in JavaScript

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.