14/16 What tells i to incrememnt


Apologies if this has been posed before, but I’m confused by this exercise.

I wanted to know the value of i that was making up a unique key, so I ran my own code to actually display the value of i, and noticed that it was essentially just an integer that incremented for each list item, so it appeared as

I just wanted to know what is it that causes the value to automatically increment, since ‘i’ is not declared anywhere else in the code.

Just for my understanding, and help would be appreciated.



Please post a link to the exercise.

If there is a loop, then i is declared in the loop parameters.


This is the final result for the exercise.

import React from ‘react’;
import ReactDOM from ‘react-dom’;

const people = [‘Rowe’, ‘Prevost’, ‘Gare’];

const peopleLis = people.map((person, i) =>
// expression goes here:

  • {person}
  • );

    // ReactDOM.render goes here:

    , document.getElementById(‘app’));




    map() is an iterator that returns a new list mapped over and computed from the old list

    const peopleLis = people.map((person, i) =>
      // expression goes here:
      <li key={'person_' + i}></li>
    // ReactDOM.render goes here:
    ReactDOM.render(<ul>{peopleLis}</ul>, document.getElementById('app'));

    i (the second parameter) is a placeholder for the internal index kept by map().


    This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.