Last post May 12, 2020 11:25 PM by EnenDaveyBoy
Participant
1861 Points
2836 Posts
May 08, 2020 11:40 PM|EnenDaveyBoy|LINK
hi
I have a functional component which use react-lodash Map to iteerate through an object which is a list of objects, but i would like an index in it and I am going round in circles
return ( <nav> <ul> <IsEmpty value={data} yes="Empty list" no={() => ( <Map collection={data} iteratee={(obj, key) => <li>{index}</li> } /> )} /> </ul> </nav> )
i know i could use my keys but my keys are descriptive and i would prefer my index to be numeric, any thoughts would be appiciated
All-Star
58194 Points
15661 Posts
May 11, 2020 02:55 PM|bruce (sqlwork.com)|LINK
just convert the mapped object to an array
<Map collection={Object.entries(data)} iteratee={(entity, index) => <li>{index} - {entity.key} - {entity.value}</li> } />
May 12, 2020 11:25 PM|EnenDaveyBoy|LINK
thanks
Participant
1861 Points
2836 Posts
can i get an index in a map?
May 08, 2020 11:40 PM|EnenDaveyBoy|LINK
hi
I have a functional component which use react-lodash Map to iteerate through an object which is a list of objects, but i would like an index in it and I am going round in circles
i know i could use my keys but my keys are descriptive and i would prefer my index to be numeric, any thoughts would be appiciated
All-Star
58194 Points
15661 Posts
Re: can i get an index in a map?
May 11, 2020 02:55 PM|bruce (sqlwork.com)|LINK
just convert the mapped object to an array
Participant
1861 Points
2836 Posts
Re: can i get an index in a map?
May 12, 2020 11:25 PM|EnenDaveyBoy|LINK
thanks