Get object property values to a new array from an array of objects. Use state in react js and update array by looping through object properties. Set state by spreading the prevState (previous state values) of an Array.
Example 1:
props.setResidentList(prevState => [...prevState, student])
Example 2:
const [tagList, setTagList] = useState<string[]>([]) useEffect(() => { itemList?.forEach(item => setTagList(prevState => [...prevState, item?.category?.name] ) ) }, [itemList])