Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Joao Rodrigues 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: References: <94a86543-50f2-4232-b988-c12db82404cb@googlegroups.com> <73df0840-d0e7-46c9-98c5-126d7f7562ad@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 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: >> 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. > > 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