Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #23516

Re: arr.push(obj);

Path csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail
From Joao Rodrigues <groups_jr-1@yahoo.com.br>
Newsgroups comp.lang.javascript
Subject Re: arr.push(obj);
Date Tue, 11 Mar 2014 06:59:34 -0300
Organization Aioe.org NNTP Server
Lines 36
Message-ID <lfmmq3$895$1@speranza.aioe.org> (permalink)
References <b766bb8c-c9a9-4914-bf16-fe342ef06930@googlegroups.com> <94a86543-50f2-4232-b988-c12db82404cb@googlegroups.com> <73df0840-d0e7-46c9-98c5-126d7f7562ad@googlegroups.com> <eb1fc2f6-1f49-4d8c-a71a-c0c7056fcb85@googlegroups.com>
NNTP-Posting-Host 6sCmKtmp0rL2AxgNAaWk1Q.user.speranza.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-Complaints-To abuse@aioe.org
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0
X-Notice Filtered by postfilter v. 0.8.2
Xref csiph.com comp.lang.javascript:23516

Show key headers only | View raw


On 11/03/2014 01:19, jonas.thornvall@gmail.com wrote:
> Den tisdagen den 11:e mars 2014 kl. 04:28:25 UTC+1 skrev jonas.t...@gmail.com:
>> Den tisdagen den 11:e mars 2014 kl. 04:19:49 UTC+1 skrev jonas.t...@gmail.com:
>>
>>> Den tisdagen den 11:e mars 2014 kl. 01:38:12 UTC+1 skrev jonas.t...@gmail.com:

<snip>

>> I did find a page that told that arr[-1] get the last element of array, so it seem negative indexes not allowed.

That is a misconception.

>
> I was wrong it is allowed or at least working.
>
> <script type="text/javascript">
> var arr=[];
> for (i=10;i>=-20;i--) {arr[i]=i;}
> arr[-22]=-22;
> for (i=10;i>=-22;i--) {document.write(arr[i],",");}
> </script>

According to the section 15.4 of the ECMAScript 5.1 Specification, "A 
property name P (in the form of a String value) is an array index if and 
only if ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal 
to 232−1". So, I think this is why you can set negative indices to an 
array. But the array's length property value is always a nonnegative 
integer less than 232.

Thereby, your code creates a mutilated array, and some of the native 
array methods might not work as expected. For instance, arr.length will 
return 11, and arr.join(',') will yield 0,1,2,3,4,5,6,7,8,9,10


-- 
Joao Rodrigues

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

arr.push(obj); jonas.thornvall@gmail.com - 2014-03-10 17:38 -0700
  Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-10 20:19 -0700
    Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-10 20:28 -0700
      Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-10 21:19 -0700
        Re: arr.push(obj); Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-03-11 06:59 -0300
          Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-11 16:02 +0100
            Re: arr.push(obj); Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-11 16:22 +0000
            Re: arr.push(obj); Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-03-11 13:32 -0300
  Re: arr.push(obj); "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-11 10:21 +0100
    Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 03:53 -0700
      Re: arr.push(obj); "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-11 14:03 +0100
        Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 07:45 -0700
          Re: arr.push(obj); "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-11 16:24 +0100
            Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 10:40 -0700
              Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 10:51 -0700
                Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-11 19:23 +0100
                Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 15:33 -0700
                Re: arr.push(obj); "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-12 00:37 +0100
                Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 16:46 -0700
                Re: arr.push(obj); "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-12 01:05 +0100
                Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-12 01:40 +0100
                Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-12 00:48 +0100
                Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 15:43 -0700
                Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 16:18 -0700
                Re: arr.push(obj); "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-12 00:39 +0100
                Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-12 00:52 +0100
                Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-12 00:49 +0100
                Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 17:16 -0700
                Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-12 02:07 +0100
                Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 18:13 -0700
                Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-13 02:25 +0100
                Re: arr.push(obj); Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-13 11:03 +0100
                Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-12 07:46 -0700
                Re: arr.push(obj); Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-12 01:27 +0100
                Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-12 01:44 +0100
          Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-11 16:26 +0100
            Re: arr.push(obj); Carlos Pedro <carlospedr@gmail.com> - 2014-03-11 09:21 -0700
            Re: arr.push(obj); Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-11 18:01 +0100
              Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-11 19:15 +0100
                Re: arr.push(obj); Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-11 20:32 +0100
                Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-12 01:01 +0100
                Re: arr.push(obj); Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-12 04:08 +0100
                Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-12 18:00 +0100
  Re: arr.push(obj); Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-03-11 06:24 -0300
    Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 03:47 -0700
      Re: arr.push(obj); Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-11 15:19 +0000

csiph-web