Furkan Yılmaz
Furkan Yılmaz

Reputation: 29

How can I use map filters?

I need to use map filters because I have a lot of data and I need a map in CustomerID

This is my code:

computed: {

    customerMap() {
const map = {}
        this.customeritems.forEach(e => (map[e.CustomerID] = map[e.CustomerID] || []).push(e))
        return map
   }
   }

Upvotes: 0

Views: 264

Answers (1)

Michael
Michael

Reputation: 5048

.map returns a new array of your items, in your case you could write:

customerMap() {
const map = this.customeritems.map(e => (map[e.CustomerID] = map[e.CustomerID]))
   }

Since you do not have {} in the .map function then implicitly it returns a new array with the transformation done to it.
If you need to filter meaning only return a new array that fulfils a certain requirement then use the .filter method.

Upvotes: 1

Related Questions