Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6288

How to know which iteration of the array.map I'm on?

$
0
0

I'm new to react-native.I want to use array.map() to render out some jsx in the UI.I'm looping over the API response which is as follows:

chosenProducts = [{id:1 , name:"carpet"} ,{id:24 , name:"toy"} ,{id:28 , name:"laser"} ,{id:137 , name:"map"} ,]

I use chosenProducts.map((prod)=>{some jsx}) to map over the array.but I want to add a key-value pair ex: order:1 to each product to be able to order them in the UI.

How can I dynamically add the order to them without changing the API response?

note: I'm using TypeScript

ps: I will use the order attribute to dynamically style the products. so it's not just the ordering!


Viewing all articles
Browse latest Browse all 6288

Trending Articles