# Array bug?

**URL:** https://forum.servoy.com/t/array-bug/13305
**Category:** Classic Servoy
**Created:** [December 10, 2010, 9:16am UTC](https://forum.servoy.com/t/array-bug/13305 "2010-12-10T09:16:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Marco\_R](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@Marco\_R](https://forum.servoy.com/u/Marco_R)
#### Post date: [December 10, 2010, 9:16am UTC](https://forum.servoy.com/t/array-bug/13305/1 "2010-12-10T09:16:36Z")

</div>

Hi all,

If I fill an array in this way:

```auto
	for(var i=1;i<=7;i++)
		_myArray[i] = i;

```

And I check the “.length”,I obtain 8 but the elements are 7!

if,instead,I create the array with the code:

```auto
var _myArray = new Array(1,2,3,4,5,6,7)

```

Then the “.length” returns the right number(7).

Maybe something wrong with the array index that start from 1 and end with 7? Or I’m forgotten something?  
Here a sample:  
[attachment=0]test\_array\_length.servoy[/attachment]

---

<div class="post-metadata">

### Author: ![birgit](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@birgit](https://forum.servoy.com/u/birgit)
#### Post date: [December 10, 2010, 9:26am UTC](https://forum.servoy.com/t/array-bug/13305/2 "2010-12-10T09:26:42Z")

</div>

You are right. The problem is the index. JavaScript Arrays always start at index 0.  
E.g.:

```auto
var myArray = [1,2,3,4]; // myArray.length is 4, indexes range from 0 to 3.
myArray[8] = 8; // myArray.length is now 9, myArray[4]..myArray[7] are undefined

```

Regards

---

<div class="post-metadata">

### Author: ![Marco\_R](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@Marco\_R](https://forum.servoy.com/u/Marco_R)
#### Post date: [December 10, 2010, 9:57am UTC](https://forum.servoy.com/t/array-bug/13305/3 "2010-12-10T09:57:59Z")

</div>

Thanks for your answer Birgit! ![:)]( "Smile")

So because this is a JavaScript’s behavior ,we have to take it as it is,right?

I’m using other count logic (a simple “for in”), I’m asking it just for knowledge

---

<div class="post-metadata">

### Author: ![birgit](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@birgit](https://forum.servoy.com/u/birgit)
#### Post date: [December 10, 2010, 10:12am UTC](https://forum.servoy.com/t/array-bug/13305/4 "2010-12-10T10:12:28Z")

</div>

Array behaviour is different in almost every language. An interesting link showing this is:

> **[Comparison of programming languages (array)](https://en.wikipedia.org/wiki/Comparison_of_programming_languages_(array))**
>
> This comparison of programming languages (array) compares the features of array data structures or matrix processing for various computer programming languages.
> The following list contains syntax examples of how to determine the dimensions (index of the first element, the last element or the size in elements).
> Some languages index from zero. Some index from one. Some carry no such restriction, or even allow indexing by any enumerated type, not only integers. 
> 2 UPB nameetc.

Regards
