DEV Community

Cover image for List and Keys
Aditya Sharan
Aditya Sharan

Posted on

List and Keys

We can output lists using Javascript arrays and the map() function. The map() is used to traverse through an array.

Below is a basic list component that accepts an array of numbers and outputs a list of elements.

Alt Text

  • A key is a special string attribute you need to include when creating lists of elements,as you must have also seen in the last.
  • Keys help React identify which items have changed, or are removed.
  • Keys should be given to the elements inside an array to give the elements a stable identity.

When you don't have stable IDs or a suitable property to be used as key for the rendered items, you may use the item index as a key as last resort :

Alt Text

That's all Thanks for reading !!

Top comments (0)