Filter Array of JSON Objects by Attributes Javascript

This post will explain how to filter array of JSON Objects by attibutes using Javascript

Suppose we have the following example of array of json objects

let json = {
    'items': [{
            "SKU": "1XFGER",
            "price": "925",
            "warehouse": "1100"
        }, {
            "SKU: "2XDERF",
            "price": "1425",
            "warehouse":"1101"
        }, {
            "SKU: "2XDESD",
            "price": "700",
            "warehouse":"1100"
        },
  
    ]
}

You want to filter out for eg: only items which fall into a specific price category or in a specific warehouse

json.items.filter(
      item=> item.price > 900,
    )
json.items.filter(
      item=> item.warehouse = 1100,
    )

Hope you liked this post on array filters. Please read on array modifications in other posts.

Leave a Reply