I have a function "Next "that maps an array like in the example below and after incrementing the element I am doing something, but I also have another function "Prev" it pretty much does a similar mapping but in that function, I am decrementing the element. The Next function works fine but the Prev function doesn't, can someone please help me with this?
I am mapping an array of object
[ {"id":"v82b3a65","name":"Name" }, {"id":"u0b26551","name":"Name2" }]
my functions :
const Next = () => { array.items.map((item, key, element) => { var next = element[key ++]; setId(next.id); });};const Prev = () => { array.items.map((item, key, element) => { var prev = element[key --]; setId(prev.id); });};render(<View><Button title={'Prev'} onPress={Prev}/><Button title={'Next'} onPress={Next}/></View>)
I am using those functions in onPress of buttons
The result I need: on Next button press I want it to set setID = next objects id and on Prev button press I want to set setID = previous object id