0

I tried to get only first element [0] of array and print in UI. I will get only first lesson in the array and then print.

{route.params.Lessons.map((lessons) => {
              return (
                <View>
                  <Text style={styles.lessonTitle}>Lesson 1</Text>
                  <Text style={styles.lessonDescription}>{lessons.lessonName}</Text>
                </View>
              )
            })}

enter image description here

Thanks

7
  • Your question is unclear. Can you elaborate on the issue? Commented Dec 28, 2021 at 9:31
  • can you add your expected result? Commented Dec 28, 2021 at 9:33
  • why don't you create an object of arrays? Commented Dec 28, 2021 at 9:34
  • @Dylan, Get only First lesson name Commented Dec 28, 2021 at 9:37
  • you want to display only the first element of array [0] instead all of them? Commented Dec 28, 2021 at 9:37

3 Answers 3

1

You could use something like this code:

<View>
  <Text style={styles.lessonTitle}>Lesson 1</Text>
  <Text style={styles.lessonDescription}>{route.params.Lessons[0].lessonName}</Text>
</View>
Sign up to request clarification or add additional context in comments.

Comments

0

If you only want to display only one element of array, you don't need to use the .map() function

You can try this instead

const lesson1 = route.params.Lessons[0]

return (
    <View>
        <Text style={styles.lessonTitle}>Lesson 1</Text>
        <Text style={styles.lessonDescription}>{lesson1.lessonName}</Text>
    </View>
)

Comments

0

Simply solved!

const LessonList = route.params.Lessons;

return (
    <View>
        <Text style={styles.lessonTitle}>Lesson 1</Text>
        <Text style={styles.lessonDescription}>{Lessons[0].lessonName}</Text>
    </View>
       )

I hope you find an answer :D

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.