Chrome Extension

Get index in map React

function items() {
    const nums = [1, 2, 3, 4];
    return <div>
        {nums.map( (num, index) => 
            <div key={index.toString()}>{num}</div>
        )}
    </div>;
}
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

In the map function, you can find the index as its second parameter. 

Was this helpful?
0 Comments