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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:41:14+00:00 2026-06-01T12:41:14+00:00

How can I remove an object from an array? I wish to remove the

  • 0

How can I remove an object from an array?
I wish to remove the object that includes name Kristian from someArray. For example:

someArray = [{name:"Kristian", lines:"2,5,10"},
             {name:"John", lines:"1,19,26,96"}];

I want to achieve:

someArray = [{name:"John", lines:"1,19,26,96"}];
  • 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-01T12:41:15+00:00Added an answer on June 1, 2026 at 12:41 pm

    You can use several methods to remove item(s) from an Array:

    //1
    someArray.shift(); // first element removed
    //2
    someArray = someArray.slice(1); // first element removed
    //3
    someArray.splice(0, 1); // first element removed
    //4
    someArray.pop(); // last element removed
    //5
    someArray = someArray.slice(0, someArray.length - 1); // last element removed
    //6
    someArray.length = someArray.length - 1; // last element removed
    

    If you want to remove element at position x, use:

    someArray.splice(x, 1);
    

    Or

    someArray = someArray.slice(0, x).concat(someArray.slice(-x));
    

    Reply to the comment of @chill182: you can remove one or more elements from an array using Array.filter, or Array.splice combined with Array.findIndex (see MDN).

    See this Stackblitz project or the snippet below:

    // non destructive filter > noJohn = John removed, but someArray will not change
    let someArray = getArray();
    let noJohn = someArray.filter( el => el.name !== "John" ); 
    log(`let noJohn = someArray.filter( el => el.name !== "John")`,
      `non destructive filter [noJohn] =`, format(noJohn));
    log(`**someArray.length ${someArray.length}`);
    
    // destructive filter/reassign John removed > someArray2 =
    let someArray2 = getArray();
    someArray2 = someArray2.filter( el => el.name !== "John" );
    log("", 
      `someArray2 = someArray2.filter( el => el.name !== "John" )`,
      `destructive filter/reassign John removed [someArray2] =`, 
      format(someArray2));
    log(`**someArray2.length after filter ${someArray2.length}`);
    
    // destructive splice /w findIndex Brian remains > someArray3 =
    let someArray3 = getArray();
    someArray3.splice(someArray3.findIndex(v => v.name === "Kristian"), 1);
    someArray3.splice(someArray3.findIndex(v => v.name === "John"), 1);
    log("",
      `someArray3.splice(someArray3.findIndex(v => v.name === "Kristian"), 1),`,
      `destructive splice /w findIndex Brian remains [someArray3] =`, 
      format(someArray3));
    log(`**someArray3.length after splice ${someArray3.length}`);
    
    // if you're not sure about the contents of your array, 
    // you should check the results of findIndex first
    let someArray4 = getArray();
    const indx = someArray4.findIndex(v => v.name === "Michael");
    someArray4.splice(indx, indx >= 0 ? 1 : 0);
    log("", `someArray4.splice(indx, indx >= 0 ? 1 : 0)`,
      `check findIndex result first [someArray4] = (nothing is removed)`,
      format(someArray4));
    log(`**someArray4.length (should still be 3) ${someArray4.length}`);
    
    // -- helpers -- 
    function format(obj) {
      return JSON.stringify(obj, null, " ");
    }
    
    function log(...txt) {
      document.querySelector("pre").textContent += `${txt.join("\n")}\n`
    }
    
    function getArray() {
      return [ {name: "Kristian", lines: "2,5,10"},
               {name: "John", lines: "1,19,26,96"},
               {name: "Brian", lines: "3,9,62,36"} ];
    }
    <pre>
    **Results**
    
    </pre>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using GCC, how can I remove a symbol from a shared object after I've
I'd like to remove the dbo prefix from the Object Explorer so I can
Is there a way to generically remove an object from an array? (maybe not
How to remove item from jquery array object. I used splice method as follows.
Using KnockoutJS, how can I remove an item from an observable array? I want
I am trying to remove an object from an array, but for some reason
How to I can remove posts from a specific category from homepages in wordpress?
I am looking for an API that can remove bundle items added in a
Is it possible to swap a reference of an object that an array element
I have an object that act on UserDefaults. It adds things into an Array

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.