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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:34:27+00:00 2026-05-25T10:34:27+00:00

What is the most general methodology (possibly in javascript) to remove an object literal

  • 0

What is the most general methodology (possibly in javascript) to remove an “object literal” from an array of “objects literal”, I mean how to determine what the index of the object to be removed is.

The keys are the same, only the values can change.

Lets suppose we have

arrObj = [{k: "a"},{k: "b"},{k: "c"},{k: "d"}]; //{k: "a"}

is just an example of oject literals, but each object could be also more nested like this

{k: "a", {y: {z: "c"}} }

I want to define a function literal which is able to make this stuff:

var removeObjFromArray = function (obj){ ... };    
arrObj.removeObjFromArray({k: "b"}); // {k: "a"},{k: "c"},{k: "d"}
  • 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-25T10:34:27+00:00Added an answer on May 25, 2026 at 10:34 am

    There’s probably a much better way of doing whatever it is you’re doing. To achieve the solution you want here, you need to iterate over the array and then compare the object. One solution is to use JSON, although you would see a performance hit in older browsers that need the compatibility shim. This is only a viable solution if you don’t need to compare functions. Something like this should work:

    function removeFromArray(arr, obj) {
        obj = JSON.stringify(obj);
        for (var i=0, max = arr.length; i < max; i++) {
            if (JSON.stringify(arr[i]) === obj)
                arr.splice(i, 1);
        }
    }
    

    Working example: http://jsfiddle.net/4JmzV/

    Note that, as cdhowie mentions in the comments, order of iteration is a factor with JSON and object properties would need to be defined in the same order. However, without JSON, you’d have to iterate over each object’s keys and iterate over the object passed in the argument several times to ensure both objects contain the same keys and same values, making it a more complex task and much slower vs native JSON.

    As I said in my first sentence, “There’s probably a much better way of doing whatever it is you’re doing”, and you might be better off taking another look at your approach.

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

Sidebar

Related Questions

In general I think I can convey most programming related concepts quite well. Yet,
We started a new project and realized that we needed a general purpose javascript
What is the most general and simple approach to make look fatter a face
As (hopefully) most of you know, floating point arithmetic is different from real number
The database which I report from most often is not properly typed. Almost every
I'm trying to determine the best general approach for querying against joined two tables
Most of my C/C++ development involves monolithic module files and absolutely no classes whatsoever,
Most of time we represent concepts which can never be less than 0. For
Most program languages have some kind of exception handling; some languages have return codes,
Most mature C++ projects seem to have an own reflection and attribute system ,

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.