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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:46:09+00:00 2026-05-19T21:46:09+00:00

I have a JavaScript array of objects with the same properties each, something like

  • 0

I have a JavaScript array of objects with the same properties each, something like this:

box[0] = { name: 'somename', /* more properties... */ };
box[1] = { name: 'othername', /* more properties... */ };
box[2] = { name: 'onemorename', /* more properties... */ };
// more objects in the array...

I want to subset this array so that it only contains objects that match a “list” of names and copy the ones that don’t to another array named cache maybe. I was thinking maybe I could compare this array of objects to another array which just contains a list of strings with the desired names to match against, checking each object’s name property against this list to create a new array with the ones that matched. I don’t know if this would work or if it is the best approach to achieve what I want, that is why I am asking for your help. Maybe checking each of 200-500 objects against a list with 100 names is not a very good thing to do, I don’t know really.

Do you have any ideas on how I could do this? even better, can you point me to an example?

Thanks in advance.

  • 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-19T21:46:09+00:00Added an answer on May 19, 2026 at 9:46 pm

    Assuming the list of names you do want are stored in an array,

    var wantedNames = [ "first name", "second name", .. ];
    

    have two arrays – those matching a name and those that don’t. Loop through each item in the box object, and if it contains a name from the list, then include it.

    var objectsMatchingName = box.filter(function(item) {
        return wantedNames.indexOf(item.name) !== -1;
    });
    
    var cache = box.filter(function(item) {
        return objectsMatchingName.indexOf(item) === -1;
    });
    

    I wish there was a array difference operation of some kind, so you could do (in pseudocode):

    var cache = box - objectsMatchingName
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object in Javascript that looks like this function MyObject(){ this.name=; this.id=0;
I'm creating my own JavaScript Array-like object and I have methods that call closures.
I have a one-dimensional array of strings in JavaScript that I'd like to turn
I have a number of objects collected in an array. The same objects are
I have a Javascript object called TweenManager which contains an array of Tween objects.
Is there a way in JavaScript to have something like an event that listens
I have an array of objects in Javascript. Can I change the object values
In javascript, I have an array of objects that represents an arbitrarily deep list...
In javascript I have an array as follows: var foo = [2, 2, 4,
I have an external JavaScript that contains: function random_imglink(){ var myimages=new Array() myimages[1]="http://sevir.sitegoz.com/jchs/Banner1.png" myimages[2]="http://sevir.sitegoz.com/jchs/banner2.png"

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.