How to use the filter() method In Javascript
The filter() method is an array method that allows you to iterate over each element in an array and return a new array with only the elements that meet some condition. You can use filter() to create a new array of objects that meet some condition based on their properties.
Example: The below example demonstrates How to get values from specific objects inside an array in JS Using the filter() method.
Javascript
const course = [ { name: "Java" , fees: 25000 }, { name: "C++" , fees: 30000 }, { name: "Python" , fees: 35000 }, ]; const courses =course .filter((obj) => obj.fees >= 30000) .map((filObj) => filObj.name); console.log(courses); |
Output
[ 'C++', 'Python' ]
How to get Values from Specific Objects an Array in JavaScript ?
In JavaScript, an array is a data structure that can hold a collection of values, which can be of any data type, including numbers, strings, and objects. When an array contains objects, it is called an array of objects.
Table of Content
- Using the forEach() method
- Using the map() method
- Using the filter() method
Contact Us