# Accessing an element in a "for" loop in js

**URL:** <https://forum.kirupa.com/t/accessing-an-element-in-a-for-loop-in-js/652750>\
**Category:** programming\
**Created:** [July 23, 2022, 9:02pm UTC](https://forum.kirupa.com/t/accessing-an-element-in-a-for-loop-in-js/652750 "2022-07-23T21:02:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GribokT\_T](https://avatars.discourse-cdn.com/v4/letter/g/e68b1a/32.png) [@GribokT\_T](https://forum.kirupa.com/u/GribokT_T)\
**Post date:** [July 23, 2022, 9:02pm UTC](https://forum.kirupa.com/t/accessing-an-element-in-a-for-loop-in-js/652750/1 "2022-07-23T21:02:01Z")

</div>

How to refer to a single element in a “for” loop in js?  
For example:

let count = 0;

do {  
document.writeln('hello   
');  
count++;  
} while (count \< 7);

how to address for example to the 3 element?

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [July 23, 2022, 9:04pm UTC](https://forum.kirupa.com/t/accessing-an-element-in-a-for-loop-in-js/652750/2 "2022-07-23T21:04:02Z")

</div>

Hi @GribokT_T - welcome to the forums 🙂

What you have is a do/while loop which is different than a for loop In a for loop, you can access the item by referring to what is known as the index position. Take a look at this article that will explain this further: [For, While, and Do...While Loops](https://www.kirupa.com/html5/loops_in_javascript.htm)

Let me know if that helps answer your question. If not, please do reply back and we can look at this further.

Cheers,  
Kirupa
