Skip to main content

Posts

Showing posts with the label how to run a loop in LWC.

Template Looping in LWC

 There are 2 types of template looping in LWC 1. for:each 2. iterator For Each < template for:each = {array} for:item = "currentItem" for:index = "index" > // we can add repeatable components </ template > Note-  1. for:each attribute take array as input 2. for item represent the current item of the loop, currentItem is the alias name, we can name to anything. 3. for:index holds index of current element of an array. Importance of Key attribute in Template loop Key is a special string/integer attribute required to be included to first element inside template when creating list of elements. Key help LWC engine to identify which items added,removed or modified. Key must be string or integer, It cant be object. Array Index cant be defined as key. < template >     < lightning-card title = "Best Companies" >         < div class = "slds-m-around_medium" >             < template for:each...