About this question
This question explains how to use the filter() method to extract objects from an array that meet certain criteria—such as matching values, ranges, or key presence.
This question explains how to use the filter() method to extract objects from an array that meet certain criteria—such as matching values, ranges, or key presence.
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask Java Expert
Answered on Jul 10, 2025
Filtering an array of objects in JavaScript is super common—whether you're working with product lists, user profiles, or API responses. Thankfully, JavaScript makes this really easy with the built-in .filter() method.
Basic Syntax
const filteredArray = array.filter(item => condition);Example: Filter Users by Age
const users = [
{ name: "Alice", age: 25 },
{ name: "Bob", age: 17 },
{ name: "Charlie", age: 30 }
];
const adults = users.filter(user => user.age >= 18);
console.log(adults);
// Output: [{ name: "Alice", age: 25 }, { name: "Charlie", age: 30 }] Why Use .filter()?
It's clean, readable, and doesn’t mutate the original array.
Useful for:
In short, .filter() is your go-to tool for narrowing down an array of objects based on custom logic. It keeps your code concise and expressive—perfect for modern JavaScript development!
Luciano Flat Latest answer
Answered on Jul 18, 2025
Ever need to quickly weed out unwanted items from a list? I did! How do you do it in Javascript? .filter() is your friend. I used it to remove inactive users from a user array once, making report generation much cleaner.
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Most-read guides across JanBask
Common Java interview questions, answered
Guides, tips and career advice on Java from JanBask experts.
Java Frequently Asked J2EE Interview Questions and Answers You Must Read
Top 45 frequently asked Java J2EE interview questions to ace your interview. These J2EE questions are useful for freshers and…
Java Top 100+ Angular Interview Questions and Answers
Are you preparing for your next Angular interview? We have compiled the list of the top 100+ Angular Interview Questions &…
Java Top 51+ Simple Java Project Ideas for Beginners In 2025
Enhance your Java skills with our top 51+ project ideas! From beginner-friendly exercises to advanced applications, fuel your…
Java How Long Does It Takes To Learn Java?
Confused about How long does it take to learn Java ? Well, No worries! This blog will guide you with valuable information and…