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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:51:21+00:00 2026-05-30T05:51:21+00:00

3 hours ago, I asked a question in SO , about deleting a part

  • 0

3 hours ago, I asked a question in SO , about deleting a part of an object, so I linked this question to it:

delete a part of object in javascript

but now another problem occurred when I deleted from that array.
I use that object to populate a FlexiGrid. but when I delete an item from that object by following code, instead of delete that item , it sets to undefined 🙁 and flexigrid did not accept it for input data.

for (var i = 0; i < Roomdata.length; i++) {

    if(Roomdata[i].id = X) {

        delete Roomdata[i];
        break;

    }
}                

For example, imagine I have 3 items in Roomdata like this :

{item1, item2, item3}

When I call this code to delete item2 , Roomdata object looks like this :

{item1, undefined, item3}

and this is a bad format to be accepted by flexigrid as input data

Is there any solution ?

Thanks every body and sorry about my bad syntax (I am new in English)

regards , Foroughi

  • 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-30T05:51:23+00:00Added an answer on May 30, 2026 at 5:51 am

    Walk through the array in reverse order, and use .splice to remove the element.
    You have to walk in the reverse order, because otherwise you end up skipping elements See below.

    for (var i = Roomdata.length-1; i >= 0; i--) {
        if (Roomdata[i].id == X) {
            Roomdata.splice(i, 1);
            break;
        }
    }
    

    What happens if you don’t walk in the reverse order:

    // This happens in a for(;;) loop:
    // Variable init:
    var array = [1, 2, 3];
    var i = 0;
    
    array.splice(i, 1); // array = [2, 3]   array.length = 2
    // i < 2, so continue
    i++;  // i = 1    
    
    array.splice(i, 1); // i=1, so removes item at place 1: array = [2]
    // i < 1 is false, so stop.
    
    // array = [2]. You have skipped one element.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just asked this question an hour ago but with regards to IE8
Based on this SO question asked a few hours ago, I have decided to
I asked a question an hour or two ago that is similar but this
A few hours ago I asked this question . I learned that std::vector deletes
Hello Everybody i asked this question few hours ago C# get username from string.
This is an extension for this question asked an hour ago. We cannot modify
It's almost a year ago that I asked this question on SO: Menu Accelerator
In asking a question about reflection I asked: Nice answer. But there is a
I had this almost working several hours ago, but I can't seem to get
About an hour ago i asked a question on rails associations: Question on Proper

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.