While I know that using a loop can achieve this functionality, I am curious if there is a built-in function that can provide the same outcome as my code below:
const openExerciseListModal = (index:number) =>{
let selectedValue = selectedItems[index];
items.forEach((element,index) => {
if(element.value===selectedValue){
alert(index)
}
});
savedExercises = [...selectedExercise]
setExerciseListModalVisible(() => !isExerciseListModalVisible)
The structure of my array looks like this:
[{ label: "Monday", value: "Monday" },{ label: "Tuesday", value: "Tuesday" }]
My objective is to click a button on the screen and obtain the index of the corresponding item in my array. For example, pressing on Monday should return 0.