Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How does filter works in javascript?

const products = [
    { name: 'Laptop', price: 32000, brand: 'Lenovo', color: 'Silver' },
    { name: 'Phone', price: 700, brand: 'Iphone', color: 'Golden' },
    { name: 'Watch', price: 3000, brand: 'Casio', color: 'Yellow' },
    { name: 'Aunglass', price: 300, brand: 'Ribon', color: 'Blue' },
    { name: 'Camera', price: 9000, brand: 'Lenovo', color: 'Gray' },
];
//Get products that price is greater than 3000 by using a filter
const getProduct = products.filter(product => product.price > 3000);
console.log(getProduct)
//Expected output:
/*[
    { name: 'Laptop', price: 32000, brand: 'Lenovo', color: 'Silver' },
    { name: 'Camera', price: 9000, brand: 'Lenovo', color: 'Gray' }
  ]
*/
Comment

How to filter data using javascript

result = homes.
  filter(function(p) { return p.price >= 150000 }).
  filter(function(p) { return p.price <= 400000 }).
  filter(function(p) { return p.bathrooms >= 2.5 }) etc
Comment

PREVIOUS NEXT
Code Example
Javascript :: loopback 
Javascript :: javascript link detector 
Javascript :: update property of object in array javascript 
Javascript :: react createelement 
Javascript :: not .js 
Javascript :: dynamic useState in react 
Javascript :: mdn trimstart 
Javascript :: map values in range js 
Javascript :: type of jvascript data 
Javascript :: javascript eval alternative 
Javascript :: js try without catch 
Javascript :: autocomplete html in react 
Javascript :: longest word in a string 
Javascript :: foreach await js 
Javascript :: modal javascript 
Javascript :: delete item from array of objects javascript 
Javascript :: replace spaces with dashes 
Javascript :: leaflet js 
Javascript :: arrow function example 
Javascript :: how to rerender a page in React when the user clicks the back button 
Javascript :: onclick call function react 
Javascript :: hi;ight word in textarea javascript 
Javascript :: javascript best online game engine 
Javascript :: Javascript "For..in Loop" Syntax 
Javascript :: getattribute 
Javascript :: React useEffect() the side-effect runs after every rendering 
Javascript :: rename files in folder 
Javascript :: factory function in javascript 
Javascript :: javascript get all options from select 
Javascript :: props history 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =