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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:48:11+00:00 2026-05-17T01:48:11+00:00

Is there a way to generically remove an object from an array? (maybe not

  • 0

Is there a way to generically remove an object from an array?
(maybe not using array.filter or creating a new array)

Example:

var arr:Array= new Array();    
//create dummy objs
for (var i:uint=0; i < 10; i++){
            var someObject:SomeClassObject = new SomeClassObject();
            someObject.Name ="Amit"+ i;
            someObject.Site="http://www.mysite.com/"+i;
           //...many more props
            arr.push(someObject);
 }
//
removeElement("Amit4",arr);
removeElement("Amit8",arr);
//...so on so forth

Currently im using array.splice() to remove object

for (var i:Number=0; i < arr.length; i++)
    {
        if (arr[i].Name == element)
        {
            arr.splice(i, 1);
        }               
    }

I want to write removeElement in such a way that i can use it for different
types of objects.
currently removeElement becomes dependant on implmentation..
Suppose if i want to remove a file from array of files given file name..i wud have to
again write “removeElement” by changing criteria.

Also may be i can vary the criteria varing criteria?
example :

arr= removeElement("Site","http://www.mysite.com/6",arr)

will remove object from arr whose “Site” property is equal to “http://www.mysite.com/6&#8221;
(using above example)

ie. removeElement(criteria:object,criteria_value(s):object,arr)

Thanks All.

  • 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-17T01:48:12+00:00Added an answer on May 17, 2026 at 1:48 am

    I think the most flexible approach is the one followed by Array::filter. It’s up to the caller to determine whether an item should be filtered out of the list or not, through a function callback.

    Now, if you want to do it in place, you could write a simple function like this:

    function remove(list:Array,callback:Function):Array {
        for(var i:int = list.length - 1; i >= 0; i--) {
            if(!callback(list[i])) {
                list.splice(i,1);
            }
        }
        return list;
    }
    

    This returns the list, as it could be convenient if you wanted to chain calls, but it acts on the array you passed instead of creating a new one.

    Also note that it loops backwards. Otherwise, splice will get you bogus results.

    You could use it like this:

    var arr:Array = [1,2,9,10,455];
    trace(arr);
    
    function removeCallback(item:Number):Boolean {
        return item < 10;
    }
    remove(arr,removeCallback);
    trace(arr);
    

    This way you are not restricted to equality (or inequality). The caller determines if the item should be kept or removed, by returning true or false respectively (to match filter). So, it’s pretty much like filter, except it works in-place. If you want, you could also keep the same interface for the callback (passing the index of the item and a reference to the original array) to make it more coherent.

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

Sidebar

Related Questions

Is there a way to generically obtain a Scala type's manifest? For example, if
Is there a quick way to remove all of the comments from a Coldfusion
Is there a succinct way, or a generally accepted way to convert from a
Is there way to get file from windows xp command prompt? I tried to
is there way how to get name ov event from Lambda expression like with
Is there a way to write interface-based code (i.e. using interfaces rather than classes
Is there a faster way to remove a directory then simply submitting rm -r
I'm wondering if there is a better/inbuilt way, other than using a byte buffer
Is there a way in .net to refer to a control generically (so that
Is there an easy way to use python string formatting from within a django

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.