You can use the filter()
method in JavaScript to get all the rows of an array of objects that contain a given field/value. The filter()
method creates a new array with all elements that pass the test implemented by the provided function.
Here's an example:
let array = [
{ name: 'John', age: 25 },
{ name: 'Jane', age: 30 },
{ name: 'Doe', age: 25 },
// other objects...
];
let results = array.filter(item => item.age === 25);
//Displays [{"name": "John", "age": 25},{"name": "Doe","age": 25}]
console.log(results);
In this example, results
will be an array containing all objects from the original array where the age
field is 25
. You can replace item.age === 25
with any condition you need.