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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:58:43+00:00 2026-06-06T02:58:43+00:00

Hello I was trying to remove objects from object array that I have and

  • 0

Hello I was trying to remove objects from object array that I have and then create another new object (I’m using $.map() to create the new object )

to remove this object from object(x) it’s object.number has to match one of the number the number in array(y)

this following code works but i only remove the object that has the object.number = 40
DEMO

Code :

   var x =[ //this is the object 
  {name : 'mark' , number : '10' , color:'green'},
  {name : 'jeff' , number : '15' , color:'blue'} ,
  {name : 'joy' , number : '30' , color:'yellow'},
  {name : 'mick' , number : '15' , color:'red'},
  {name : 'mick' , number : '40' , color:'black'}] ; 

      var y =['40','15']; // i need to remove all object.number that match the 
        // number in this array

     var newObject = $.map(x  ,function(index, value){
        for(i in y){
         if(index.number == y[i])
        {return null ; }
       else{
        return index;
            }      
      }

    });
 console.log(newObject);​

the code above only remove the object that has 40 in it’s object.number, how can i make this work?

  • 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-06T02:58:44+00:00Added an answer on June 6, 2026 at 2:58 am

    This is what you want:

    var newObject = $.map(x  ,function(index, value){
        for(i in y){
            if(index.number == y[i])
                return null;
        }
        return index;
    });
    console.log(newObject);​
    

    and jsFiddle. By the way: I think using for(i in y) for arrays is not a good practice (arrays may have other properties). You should use standard:

    var l = y.length;
    for(var i = 0; i < l; i++){
        /* the other code */
    }
    

    Note the length caching.

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

Sidebar

Related Questions

I am trying to remove quotes from something like: Hello so that the string
Hello i was trying to modify an object form the values of another object
I'm trying to remove excess whitespace from a string like this: hello        world
I have a mongodb object as follows: array ( '_id' => new MongoId(4cc97fb0247ae8747ec5fefb), 'posts'
I am trying to remove quotes from a string. Example: hello, how 'are you
hello i am trying to load a list of filenames from a folder into
Hello I am trying to create a custom expandable listview, but the documentation on
Hello I am trying to setup a Padrino project using DataMapper and MySQL on
Hello i'm trying to use autocomplete dropdownlist plugin that name is ufd. Anyway, I
SO, I'm trying to create a javascript object, and use the setInterval method. This

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.