0

Technically, I know how to filter in reactjs, but now I want to go a little further and filter something more advance. Using this method I can filter on the json but I have problem to access to price

//work fine
{product.filter(person => person.id >1)).map(filteredPerson =>  (
 <li>
     { filteredPerson.name }
    </li>)) }
// 'person.cena.includes' is undefined)
{product.filter(person => person.cena.includes("100kw")).map(filteredPerson =>  (
 <li>
     { filteredPerson.name }
    </li>)) }



const product = [{name: "abc",
id: 0,
price: {
"100kW": 3432,
"200kW": 4345,
"300kW": 5456}},
{name: "cba",
id: 1,
price: {
"100kW": 2222,
"200kW": 3333,
"300kW": 4444}}] 

My goal is to achieve datatable like this: id/name/type/price 0/abc/6kw/2222/ 0/abc/8kw/3333

because I want to use if statement (in this filter method)

var maxSize = Math.ceil(power/effecienty*1.3)
var minSize = Math.ceil(power/effecienty*0.7)
if(minSize> 4 && maxSize < 8){ return product.cena.includes('6kW')}
if(minSize> 6 && maxSize < 10){ return product.cena.includes('8kW')}
...

  • For your specific case `in` is enough, so `person => "110kw" in person.cena`. – tevemadar May 09 '22 at 09:12
  • Method hasProperty and method in work perfect. But I get an error after trying map this object I try ``` {product.cena} ``` and get information ``` Objects are not valid as a React child (found: object with keys {6kw, 8kw}). If you meant to render a collection of children, use an array instead. ``` –  May 09 '22 at 09:21

0 Answers0