How to get Values from Specific Objects an Array in JavaScript ? Last Updated : 04 Mar, 2024 Comments Improve Suggest changes Like Article Like Report 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() methodUsing the map() methodUsing the filter() methodUsing the forEach() methodThe forEach() method is used to iterate through each element of an array and execute a provided function. It does not return a new array, but it's helpful when you want to operate on each element without modifying the original array. Example: The below example demonstrates how to get values from specific objects inside an array using the forEach method in JavaScript. JavaScript const courses = [ { name: 'C++', fees: 30000 }, { name: 'Python', fees: 35000 }, { name: 'JavaScript', fees: 40000 }, { name: 'Java', fees: 45000 }, ]; const cheapCourses = []; courses.forEach((course) => { if (course.fees <= 35000) { cheapCourses.push(course.name); cheapCourses.push(course.fees); } }); console.log(cheapCourses); Output[ 'C++', 30000, 'Python', 35000 ] Using the map() methodThe map() method is another array method that allows you to iterate over each element in an array and return a new array with the result of some operation on each element. You can use map() to create a new array of values from the properties of the objects in the original array. Example: The below example demonstrates How to get values from specific objects inside an array in JavaScript Using the map() method. JavaScript const course = [ { name: "Java", fees: 25000 }, { name: "C++", fees: 30000 }, { name: "Python", fees: 35000 }, ]; const courses =course .map((filObj) => filObj.name); console.log(courses); Output[ 'Java', 'C++', 'Python' ] Using the filter() methodThe 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' ] Comment More infoAdvertise with us Next Article How to get Values from Specific Objects an Array in JavaScript ? P pranay0911 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to use forEach with an Array of Objects in JavaScript ? Using the forEach() method with an array of objects in JavaScript is essential for iterating over collections and performing operations on each object. This guide explores effective techniques to utilize forEach() for array manipulation, enhancing your coding skills. Syntax: array.forEach( function( 3 min read How to store a key=> value array in JavaScript ? In JavaScript, storing a key-value array means creating an object where each key is associated with a specific value. This allows you to store and retrieve data using named keys instead of numeric indices, enabling more intuitive access to the stored information.Here are some common approaches:Table 4 min read How to get Values from HTML Input Array using JavaScript? This problem can be solved by using input tags having the same "name" attribute value that can group multiple values stored under one name which could later be accessed by using that name. Syntaxlet input = document.getElementsByName('array[]');What is an Input Array in HTML?An "input array" in HTML 2 min read How To Remove Specific JSON Object From Array JavaScript? Removing Specific JSON objects from the array is important because it allows for targeted data manipulation and maintenance within JavaScript applications. we will learn to Remove Specific JSON Object From Array JavaScript. These are the following methods: Table of Content Using filter() methodUsing 3 min read How to Convert an Array of Objects to Map in JavaScript? Here are the different methods to convert an array of objects into a Map in JavaScript1. Using new Map() ConstructorThe Map constructor can directly create a Map from an array of key-value pairs. If each object in the array has a specific key-value structure, you can map it accordingly.JavaScriptcon 3 min read How to get a key in a JavaScript object by its value ? To get a key in a JavaScript object by its value means finding the key associated with a specific value in an object. Given an object with key-value pairs, you want to identify which key corresponds to a particular value, often for searching or data retrieval.How to get a key in a JavaScript object 4 min read How to convert a map to array of objects in JavaScript? A map in JavaScript is a set of unique key and value pairs that can hold multiple values with only a single occurrence. Sometimes, you may be required to convert a map into an array of objects that contains the key-value pairs of the map as the values of the object keys. Let us discuss some methods 6 min read How to Create Array of Objects From Keys & Values of Another Object in JavaScript ? Creating an array of objects from the keys and values of another object involves transforming the key-value pairs of the original object into individual objects within an array. Each object in the array represents a key-value pair from the source object. Below approaches can be used to accomplish th 3 min read How to compare Arrays of Objects in JavaScript? In JavaScript, comparing arrays of objects can be more complex than comparing primitive data types. We will discuss different ways to compare arrays of objects effectively, with detailed code examples and explanations.Syntax: Before going to detail the comparison techniques, let's first understand h 5 min read How to Access Array of Objects in JavaScript ? Accessing an array of objects in JavaScript is a common task that involves retrieving and manipulating data stored within each object. This is essential when working with structured data, allowing developers to easily extract, update, or process information from multiple objects within an array.How 4 min read Like