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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:13:56+00:00 2026-05-23T16:13:56+00:00

If I have an array of objects is there any way possible for the

  • 0

If I have an array of objects is there any way possible for the item to splice itself out of the array that contains it?

For example: If a bad guy dies he will splice himself out of the array of active enemies.

I probably sound crazy but that ability would simplify my code dramatically, so I hope for something cool =)

  • 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-23T16:13:56+00:00Added an answer on May 23, 2026 at 4:13 pm

    The way you would do it is as follows:

    var game_state = { active_enemies: [] };
    function Enemy() {
        // Various enemy-specific things go here
    }
    Enemy.prototype.remove = function() {
        // NOTE: indexOf is not supported in all browsers (IE < 8 most importantly)
        // You will probably either want to use a shim like es5-shim.js
        // or a utility belt like Underscore.js
        var i = game_state.active_enemies.indexOf(this);
        game_state.active_enemies.splice(i, 1);
    }
    

    See:

    • Es5-Shim
    • Underscore.js

    Notta bene: There are a couple of issues here with this manner of handling game state. Make sure you are consistent (i.e. don’t have enemies remove themselves from the list of active enemies, but heroes remove enemies from the map). It will also make things more difficult to comprehend as the code gets more complex (your Enemy not only is an in-game enemy, but also a map state manager, but it’s probably not the only map state manager. When you want to make changes to how you manage map state, you want to make sure that code is structured in such a way that you only need to change it in one place [preferably]).

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

Sidebar

Related Questions

Is there any way to have nested objects in JSON so I don't have
Is there any method like the array_unique for objects? I have a bunch of
I have an Array of Objects that need the duplicates removed/filtered. I was going
I have an array of objects that have QTTime structs as attributes. The objects
I'm wondering if is there any way to mimic the same behaviour we have
I have a plugin which is applied on few element. Is there any way
Is there any portable way to determine what the maximum possible alignment for any
Is it possible, in any way, to pass a Generic Record in an array
Possible Duplicate: Java Generics: Array containing generics I have a Java class which contains
I have a JSON array with ActiveRecord objects. These objects can be reconstructed using

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.