# Unable to access the elements in an array with array\[1\]\[0\]

**URL:** <https://www.ruby-forum.com/t/unable-to-access-the-elements-in-an-array-with-array-1-0/192228>\
**Category:** Ruby\
**Created:** [July 26, 2010, 6:11pm UTC](https://www.ruby-forum.com/t/unable-to-access-the-elements-in-an-array-with-array-1-0/192228 "2010-07-26T18:11:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arti\_singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@arti\_singh](https://www.ruby-forum.com/u/arti_singh)\
**Post date:** [July 26, 2010, 6:11pm UTC](https://www.ruby-forum.com/t/unable-to-access-the-elements-in-an-array-with-array-1-0/192228/1 "2010-07-26T18:11:16Z")

</div>

I feel quite silly asking this question, but here I am. I have what I  
believe to be a 2 dimensional array, but I can not access the elements  
in the array with the array syntax array[1][0] when I select the first  
element in the array with array.first or array[1], I get  
array[[“first”,“first value”]] but I am not able to access the string  
“first” or the string “first value”

my array looks like :  
[[“first”,“first value”]]  
[[“second”,“second value”]]  
[[“third”,“third value”]]  
[[“third”,“third value”]]  
[[“fifth”,“fifth value”]]

How can I get the elements in this array? am I missing something here?

---

<div class="post-metadata">

**Author:** ![arti\_singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@arti\_singh](https://www.ruby-forum.com/u/arti_singh)\
**Post date:** [July 26, 2010, 6:27pm UTC](https://www.ruby-forum.com/t/unable-to-access-the-elements-in-an-array-with-array-1-0/192228/2 "2010-07-26T18:27:35Z")

</div>

On Mon, Jul 26, 2010 at 10:11 AM, Arti S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> [[“third”,“third value”]]  
> [[“third”,“third value”]]  
> [[“fifth”,“fifth value”]]
> 
> ## How can I get the elements in this array? am I missing something here?
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> You don’t need double brackets to declare an array.

[“first”,“first value”]  
[“second”,“second value”]  
[“third”,“third value”]  
[“third”,“third value”]  
[“fifth”,“fifth value”]

You declared an invalid multidimensional array. To declare a  
multidimensional array:

[[“first”,“first value”], [“second”,“second value”], [“third”,“third  
value”], [“third”,“third value”], [“fifth”,“fifth value”]]

Your multidimensional array looks like this:  
[[“first”,“first value”]]

The second set of brackets are closing off the first multidimensional  
array.  
At that point, you’re trying to access array[1][0], but there’s only a  
zeroeth element. Remember: the first element in any array is at offset  
0, so  
to access the first element of this multidimensional array: array[0][0]

Make sense?

James

If you’re declaring a multid

---

<div class="post-metadata">

**Author:** ![arti\_singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@arti\_singh](https://www.ruby-forum.com/u/arti_singh)\
**Post date:** [July 26, 2010, 6:42pm UTC](https://www.ruby-forum.com/t/unable-to-access-the-elements-in-an-array-with-array-1-0/192228/3 "2010-07-26T18:42:35Z")

</div>

Thanks, James. I owe you one.  
I had been reading the data from the datasource incorrectly.  
xclworksheet.Range(“A1:B20”).rows.each{|r|ea\_array.push(r.value.inspect)  
instead I should have just done  
ea\_array=xclworksheet.Range(“A1:B20”)[‘Value’]

James wrote:

> On Mon, Jul 26, 2010 at 10:11 AM, Arti S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > [[“third”,“third value”]]  
> > [[“third”,“third value”]]  
> > [[“fifth”,“fifth value”]]
> > 
> > ## How can I get the elements in this array? am I missing something here?
> > 
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > You don’t need double brackets to declare an array.
> 
> [“first”,“first value”]  
> [“second”,“second value”]  
> [“third”,“third value”]  
> [“third”,“third value”]  
> [“fifth”,“fifth value”]
> 
> You declared an invalid multidimensional array. To declare a  
> multidimensional array:
> 
> [[“first”,“first value”], [“second”,“second value”], [“third”,“third  
> value”], [“third”,“third value”], [“fifth”,“fifth value”]]
> 
> Your multidimensional array looks like this:  
> [[“first”,“first value”]]
> 
> The second set of brackets are closing off the first multidimensional  
> array.  
> At that point, you’re trying to access array[1][0], but there’s only a  
> zeroeth element. Remember: the first element in any array is at offset  
> 0, so  
> to access the first element of this multidimensional array: array[0][0]
> 
> Make sense?
> 
> James
> 
> If you’re declaring a multid
