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

How can I remove one element of an array by ID?

$
0
0

How do i remove questionList[num] of questionList? In this way I'm getting the 1 Element I don't want to have anymore.

const [questionList, setQuestionList] = useState<{question: string, id: number}[]>([]);const getNumber = () => {    const num = Math.floor(Math.random() * questionList.length);    if (num) {      const qid = questionList[num].id;      setQuestionList(questionList.filter((obj) => obj.id !== qid));      setNumber(num);      return qid;    }  };

Viewing all articles
Browse latest Browse all 6287

Trending Articles



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