I am iterating JavaScript array elements using a for loop inside a function. Below is my array.
productArray = [
{
icon: faBox,
name: 'CHANNELS',
link: '/channelList/${channelListId}',
},
{
icon: faVideo,
name: 'VOD',
link: '/vodList/${vodId}',
},
{
icon: faMusic,
name: 'MOD',
link: null,
},
]
Following function is being used to iterate the array elements.
showProductElements = () => {
for (var i = 0; i < this.productArray.length; i++) {
return (
<Link to={this.productArray[i].link}>
<div className="tableDiv">
<div className="tableCell">
<div className="channel">
<span>
<FontAwesomeIcon icon={this.productArray[i].icon}
className="blocks-fa-icon" />
</span>
<h2 className="block-header">{this.productArray[i].name}</h2>
</div>
</div>
</div>
</Link>
);
}
};
In render method I am calling the function as follows.
<div className="row">
{this.showProductElements()}
</div>
My problem is using all these fuctions and code snippests, I can only render the first object element of the array. Can anyone help me out this for solving this problem?