add a text on last object map reactjs 1

add a text on last object map reactjs

{
	   data.map((item, i, arr) => {item} {i != (arr.length-1) ? ', ' : ''})
        }

Here is what the above code is Doing:
1. We’re using the map() method to iterate over the data array.
2. We’re using the i variable to keep track of the index of the current item.
3. We’re using the arr variable to access the array itself.
4. We’re using the length property to get the length of the array.
5. We’re using the ternary operator to check if the current item is the last item in the array.
6. We’re using the comma operator to add a comma after each item except the last item.

Similar Posts