Unions and Indexing 10 exercises

Create Unions out of Array Values

We start with an array of strings called fruits:

const fruits = ["apple", "banana", "orange"]

Seeing this suggests that we're going to want the values of the array, so think about that.


Your challenge is to get a union of AppleOrBanana, as well as creating a union ou

Loading exercise


0:00 In this exercise, we have an array of fruits here. Currently they're typed as just an array of strings.

0:08 We know that we're probably going to want the values of that array, so have a little think about that. We also want to say AppleOrBanana equals unknown. We want to get a union of apple or banana in that slot.

0:21 Otherwise, we want to take all of the values of the array and put them inside Fruit. That's your challenge.