Skip to main content
1-Visitor
January 5, 2021
Question

For Each loop in ThingWorx

  • January 5, 2021
  • 2 replies
  • 3949 views

Hi Team,

 

Could somebody help me with the snippet alongwith example that how to write ForEach loop of JS in ThingWorx.

 

Suppose my array is var fruits = ["apple""orange""cherry"]; , then how to print each element (or access each element) of this array.

 

Thanks in advance.

2 replies

5-Regular Member
January 5, 2021

Hello @ranjank ,

 

Can you try using 

for (i = 0; i < fruits.length; i++) {
result = fruits[i];
}

 

Hope it helps,

ranjank1-VisitorAuthor
1-Visitor
January 5, 2021

Hi @Ciprian-Traian

 

It is a normal For Loop and I am looking for For Each loop.

 

The array which I have mentioned is just an example.

 

Please advise. 

 

13-Aquamarine
January 5, 2021

for your example the forEach synthax would be:

 

fruits.forEach (element => {
      // execute stuff for element
});

Support
January 12, 2021

Hi @ranjank.

 

If you feel your question has been answered, please mark the appropriate response as the Accepted Solution for the benefit of others with the same question.

 

Regards.

 

--Sharon