1
1 Comment

I need some help with my code!

Hey guys! im studying right now and starting with reactjs and all that, i have to make a web page based in Game of thrones using an API, i recieve the api data and i can print in screen the img, name and age of the characters, but i need to sort them by their age.

{items.filter(item=> item.age && item.age.age).map(item => (

                    <li key={item.id}>
                    <img src={item.image} alt="personajes" ></img>  Name: {item.name} | age: {item.age.age}
                    </li>

This is what i got till now, i did the filter cause there's some characters that doesnt have known age, well, i guess i have to use a sort, something like

items.sort((a,b) => a.item.age.age - b.item.age.age)

But idk how i have to exactly write it in my code and make it work, i have to make also a button where i can order from minor to major and to the reverse, thanks a lot if you can help me, i ve been with this all day yesterday, and sorry for not a perfect english, hope you can understand everything :P

on December 8, 2020
  1. 1

    I would probably go for StackOverflow instead of IH for this.