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

Is there a better way to find an specific object inside an array by name?

$
0
0

I know this could be easily done with a loop like I'm doing in the method below. I'm just wondering if there is any pre-build function that I can use to get the same result my code gets here:

const openExerciseListModal = (index:number) =>{let selectedValue = selectedItems[index];items.forEach((element,index) => {  if(element.value===selectedValue){    alert(index)  }});savedExercises = [...selectedExercise]setExerciseListModalVisible(() => !isExerciseListModalVisible)

My array is something like this:

[{ label: "Monday", value: "Monday" },{ label: "Tuesday", value: "Tuesday" }]

My goal is to click the button in my screen and get the index of that item in my array. If the user press on Monday, it gets 0 for instance.


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>