Looping through an array of objects.

    <template for:each={similarProducts} for:item="i" for:index="index">
      <div key={i.id} class="bx--col" data-field={field.type}>

Looking for a way to pass the index and type from the above for:each to the productData method

get productData() {
    return "hello";

1 Answer 1


productData is a getter, it can not take arguments. Instead of trying to get data there you will probably have to prepare a list of objects, with all properties you need, in advance and and loop over that.

  • Ok ... So is there any alternative to that getter? Something that can receive data from the html template?
    – Ciprian
    Commented Mar 30, 2022 at 10:51
  • No, in the template you can only use properties and getters. You can only read data from the template in a callback or normal function. I might be able to help you further I you can explain what you're trying to achieve instead of how you try to solve your problem.
    – H Alves
    Commented Mar 30, 2022 at 11:31

Not the answer you're looking for? Browse other questions tagged .