# Looping through variables \[solved\]

**URL:** <https://forum.wixstudio.com/t/looping-through-variables-solved/30037>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [March 26, 2020, 10:09pm UTC](https://forum.wixstudio.com/t/looping-through-variables-solved/30037 "2020-03-26T22:09:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![drcline87](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/drcline87/32/780_2.png) [@drcline87](https://forum.wixstudio.com/u/drcline87)\
**Post date:** [March 26, 2020, 10:09pm UTC](https://forum.wixstudio.com/t/looping-through-variables-solved/30037/1 "2020-03-26T22:09:25Z")

</div>

I am trying to code my site but I keep getting a “TypeError: $w(…).hide is not a function” error. Can anyone spot what I am doing wrong? I have a bunch of #html in sepquence that I am trying to hide based on a dropdown selection. I am trying to convert:

$w(“#htmlLD1”).hide();  
$w(“#htmlLD2”).hide();  
$w(“#htmlLD3”).hide();  
$w(“#htmlLD4”).hide();

Into:  
**let** myArray = [“1”, “2”, “3”, “4”];  
**for(let** i = 1; i \< myArray.length; i++){  
**let** htmlstr = “"#htmlLD”+ i + “"”;  
console.log(htmlstr)  
$w(htmlstr).hide();  
}

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [March 26, 2020, 11:00pm UTC](https://forum.wixstudio.com/t/looping-through-variables-solved/30037/2 "2020-03-26T23:00:02Z")

</div>

```javascript
let htmlstr = `#htmlLD${i}`;

```

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [March 26, 2020, 11:02pm UTC](https://forum.wixstudio.com/t/looping-through-variables-solved/30037/3 "2020-03-26T23:02:50Z")

</div>

Also the loop condition should be:  
i \<= myArray.length

---

<div class="post-metadata">

**Author:** ![drcline87](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/drcline87/32/780_2.png) [@drcline87](https://forum.wixstudio.com/u/drcline87)\
**Post date:** [March 26, 2020, 11:08pm UTC](https://forum.wixstudio.com/t/looping-through-variables-solved/30037/4 "2020-03-26T23:08:54Z")

</div>

I knew it was something simple. Thanks!

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [March 26, 2020, 11:15pm UTC](https://forum.wixstudio.com/t/looping-through-variables-solved/30037/5 "2020-03-26T23:15:35Z")

</div>

You’re welcome (I just corrected your code, but I don’t think you really need this looping + I don’t see a point in having such an array if you don’t use it, you could just loop to a certain number without having an array that you never use)
