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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:12:33+00:00 2026-06-18T09:12:33+00:00

I have an array that is stored in a key, see values format: {id:

  • 0

I have an array that is stored in a key, see values format:

{id: 0, data: mydata}

I also have a list that corresponds to that ID for deletion of a file and removal of an element.
The problem I am having is when using a Javascript splice function (to delete an object from the array) it changes the index values.

See javascript below:

function setupFileList(file, id){
    var list_of_file = document.getElementById("list_of_file");
    var name_of_file = file.name;
    var size_of_file = 0;
    var file_reader = new FileReader();
    file_reader.onload = function(e){
        var imgsrc = e.target.result;
        if(file){
            if(file.size > 1024 * 1024)
                size_of_file = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + "MB";
            else
                size_of_file = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
        }

        list_of_file.innerHTML += '<div id="file-'+id+'" class="filesUp"><img class="imgUp" src="' + imgsrc +'" width="100px" height="100px"><div class="progressUp"><span>' + name_of_file + ' / ' + size_of_file +'</span></div><a href="#" onclick="deleteUp(\''+id+'\')">Delete</a></div>';
    };
    file_reader.readAsDataURL(file);
};


function deleteUp(fid){
    var file_query = fileQuery.indexOf({id: fid});
    fileQuery.splice(file_query, 1);
    console.log(file_query);
}
  • 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-18T09:12:34+00:00Added an answer on June 18, 2026 at 9:12 am

    How about storing the objects in an object INSTEAD of an array, that way the keys are fixed.

    var fileQuery = {
       0: {
          id: 0,
          data: "some data"
       },
       1: {
          id: 1,
          data: "some more data"
       }
    };
    

    Use the delete command to remove items from the object.
    for example:

    delete fileQuery[0];
    

    ALSO indexOf does not compare the properties of objects in an array BUT rather the references of the objects themselves. This means array.indexOf returns the index of the object you give as the arg, so {id: fid} is actually creating a new unique object at that point. Unfortunately indexOf will always return -1 as it will never find the newly created object in the array.

    The best way to find the index of the object you are looking for is to manually loop through the array and compare the id property of all elements to fid. I am afraid in this case array.indexOf wont work.

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

Sidebar

Related Questions

I have a property list ( Data.plist ) that contains an array of two
I have an array of vectors that I want to be stored in Block
I have a service that converts images stored on a website to byte array
I have array with alphanumeric key values..While filling array on particular condition I have
I have written some code that stores values inside a array of arrays. I
I have a snippet of code that creates an array clusterUniqueMarkers that stores all
I have a PHP class that stores a complex multidimensional array, and rather than
I have an array that contains @sign in the object. I can't access that
I have an array that I populate with parents, children, children of children, children
I have an array that looks something like this: Array ( [0] => apple

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.