Using Map Data Structure from Request.collect

Hi there,

I’m reading Adonis documentation and I’m not sure if I’m able to use Map data structure from Request.

For example, I want to receive a structure from request like this:

[{product_id: '1', quantity: 1 }, { product_id: '2', quantity: 3 }]

Can I read using the collection above, using:

let product_quantity = request.collect(['product_id', 'quantity'])        
        
        for (const i of product_quantity.keys()){
            //do something
        } 

Is that possible? If not, how can I manipulate the data from request.collect?

Thanks

1 Like

You may have gone through a similar example in docs - https://adonisjs.com/docs/4.1/request#_request_collection

The output from collect is array of objects.

2 Likes