Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #23508 > unrolled thread
| Started by | jonas.thornvall@gmail.com |
|---|---|
| First post | 2014-03-10 17:38 -0700 |
| Last post | 2014-03-11 15:19 +0000 |
| Articles | 20 on this page of 46 — 7 participants |
Back to article view | Back to comp.lang.javascript
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
Page 1 of 3 [1] 2 3 Next page →
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-03-10 17:38 -0700 |
| Subject | arr.push(obj); |
| Message-ID | <b766bb8c-c9a9-4914-bf16-fe342ef06930@googlegroups.com> |
1. Can javascript have negative index of array[-500]?
2. If so how can i change code below to create object range from -500 to 500 as i understand it the code will will create an array with object 0-999.
for (var i = -500; i <= +500; i ++ )
{
var obj =
{
count : i,
fcolor : 'black',
rheight : 100,
rwidth : 100,
rcolor : 'white'
}
arr.push(obj);
}
3. If i want to create an object on the fly as a counter increment/decrement in the code.
Let us say obj for arr[-501] how go in todo that.
JT
[toc] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-03-10 20:19 -0700 |
| Message-ID | <94a86543-50f2-4232-b988-c12db82404cb@googlegroups.com> |
| In reply to | #23508 |
Den tisdagen den 11:e mars 2014 kl. 01:38:12 UTC+1 skrev jonas.t...@gmail.com:
> 1. Can javascript have negative index of array[-500]?
>
> 2. If so how can i change code below to create object range from -500 to 500 as i understand it the code will will create an array with object 0-999.
>
>
>
> for (var i = -500; i <= +500; i ++ )
>
> {
>
> var obj =
>
> {
>
> count : i,
>
> fcolor : 'black',
>
> rheight : 100,
>
> rwidth : 100,
>
> rcolor : 'white'
>
> }
>
>
>
> arr.push(obj);
>
> }
>
>
>
> 3. If i want to create an object on the fly as a counter increment/decrement in the code.
>
>
>
> Let us say obj for arr[-501] how go in todo that.
>
>
>
> JT
It also seem that 3. would require a negative increment of an array size, is that even possible?
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-03-10 20:28 -0700 |
| Message-ID | <73df0840-d0e7-46c9-98c5-126d7f7562ad@googlegroups.com> |
| In reply to | #23510 |
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:
>
> > 1. Can javascript have negative index of array[-500]?
>
> >
>
> > 2. If so how can i change code below to create object range from -500 to 500 as i understand it the code will will create an array with object 0-999.
>
> >
>
> >
>
> >
>
> > for (var i = -500; i <= +500; i ++ )
>
> >
>
> > {
>
> >
>
> > var obj =
>
> >
>
> > {
>
> >
>
> > count : i,
>
> >
>
> > fcolor : 'black',
>
> >
>
> > rheight : 100,
>
> >
>
> > rwidth : 100,
>
> >
>
> > rcolor : 'white'
>
> >
>
> > }
>
> >
>
> >
>
> >
>
> > arr.push(obj);
>
> >
>
> > }
>
> >
>
> >
>
> >
>
> > 3. If i want to create an object on the fly as a counter increment/decrement in the code.
>
> >
>
> >
>
> >
>
> > Let us say obj for arr[-501] how go in todo that.
>
> >
>
> >
>
> >
>
> > JT
>
>
>
> It also seem that 3. would require a negative increment of an array size, is that even possible?
arr.push(obj,i) where i is the +/- index would had been nice. Now i am not even sure that i can use objects without index translation which i find a bit strange.
I did find a page that told that arr[-1] get the last element of array, so it seem negative indexes not allowed.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-03-10 21:19 -0700 |
| Message-ID | <eb1fc2f6-1f49-4d8c-a71a-c0c7056fcb85@googlegroups.com> |
| In reply to | #23511 |
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:
>
> >
>
> > > 1. Can javascript have negative index of array[-500]?
>
> >
>
> > >
>
> >
>
> > > 2. If so how can i change code below to create object range from -500 to 500 as i understand it the code will will create an array with object 0-999.
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > > for (var i = -500; i <= +500; i ++ )
>
> >
>
> > >
>
> >
>
> > > {
>
> >
>
> > >
>
> >
>
> > > var obj =
>
> >
>
> > >
>
> >
>
> > > {
>
> >
>
> > >
>
> >
>
> > > count : i,
>
> >
>
> > >
>
> >
>
> > > fcolor : 'black',
>
> >
>
> > >
>
> >
>
> > > rheight : 100,
>
> >
>
> > >
>
> >
>
> > > rwidth : 100,
>
> >
>
> > >
>
> >
>
> > > rcolor : 'white'
>
> >
>
> > >
>
> >
>
> > > }
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > > arr.push(obj);
>
> >
>
> > >
>
> >
>
> > > }
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > > 3. If i want to create an object on the fly as a counter increment/decrement in the code.
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > > Let us say obj for arr[-501] how go in todo that.
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > > JT
>
> >
>
> >
>
> >
>
> > It also seem that 3. would require a negative increment of an array size, is that even possible?
>
>
>
> arr.push(obj,i) where i is the +/- index would had been nice. Now i am not even sure that i can use objects without index translation which i find a bit strange.
>
>
>
> I did find a page that told that arr[-1] get the last element of array, so it seem negative indexes not allowed.
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>
But howdo i push objects starting at the negative index?
And how can i add/push objects to the negative side of index?
[toc] | [prev] | [next] | [standalone]
| From | Joao Rodrigues <groups_jr-1@yahoo.com.br> |
|---|---|
| Date | 2014-03-11 06:59 -0300 |
| Message-ID | <lfmmq3$895$1@speranza.aioe.org> |
| In reply to | #23512 |
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
[toc] | [prev] | [next] | [standalone]
| From | Christoph Michael Becker <cmbecker69@arcor.de> |
|---|---|
| Date | 2014-03-11 16:02 +0100 |
| Message-ID | <531f256d$0$6670$9b4e6d93@newsspool2.arcor-online.net> |
| In reply to | #23516 |
Joao Rodrigues wrote:
> On 11/03/2014 01:19, jonas.thornvall@gmail.com wrote:
>
>> 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.
If P has a negative value, ToString(ToUint32(P)) can't be equal to P.
So there can _not_ be negative array indexes.
BTW: 232 should be written as 2^32 or 2³² in this case. :)
> 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
--
Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2014-03-11 16:22 +0000 |
| Message-ID | <0.14513509f7021ee286e0.20140311162221GMT.87d2hswvr7.fsf@bsb.me.uk> |
| In reply to | #23522 |
Christoph Michael Becker <cmbecker69@arcor.de> writes:
> Joao Rodrigues wrote:
>
>> On 11/03/2014 01:19, jonas.thornvall@gmail.com wrote:
>>
>>> 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.
>
> If P has a negative value, ToString(ToUint32(P)) can't be equal to P.
> So there can _not_ be negative array indexes.
Yes, but what's confusing Jonas is that the code "works" (I use quotes
because it only works for some rather restricted meaning of the term).
You can't have a negative array *index*, but an array can have a
*property* whose name is a string that *looks* like a negative number.
Jonas, here is an interactive session with a ES interpreter. Maybe the
last line with make the penny drop:
> var a = [1,2,3];
> a[-1] = 0;
> console.log(a)
[ 1, 2, 3, '-1': 0 ]
In the same way, you can set a[0.5] = 'half', but it won't be very
useful:
> a[0.5] = 'half';
> console.log(a)
[ 1, 2, 3, '-1': 0, '0.5': 'half' ]
> BTW: 232 should be written as 2^32 or 2³² in this case. :)
<snip>
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | Joao Rodrigues <groups_jr-1@yahoo.com.br> |
|---|---|
| Date | 2014-03-11 13:32 -0300 |
| Message-ID | <lfndqt$9te$1@speranza.aioe.org> |
| In reply to | #23522 |
On 11/03/2014 12:02, Christoph Michael Becker wrote:
> Joao Rodrigues wrote:
>
>> On 11/03/2014 01:19, jonas.thornvall@gmail.com wrote:
>>
>>> 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.
>
> If P has a negative value, ToString(ToUint32(P)) can't be equal to P.
> So there can _not_ be negative array indexes.
>
> BTW: 232 should be written as 2^32 or 2³² in this case. :)
Oh, dear! I should have checked the abstract operation ToUint32 first.
<http://www.ecma-international.org/ecma-262/5.1/#sec-9.6>
Thanks!
--
Joao Rodrigues (J.R.)
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-03-11 10:21 +0100 |
| Message-ID | <XnsA2ED695A14973eejj99@194.109.133.133> |
| In reply to | #23508 |
jonas.thornvall@gmail.com wrote on 11 mrt 2014 in comp.lang.javascript:
> 3. If i want to create an object on the fly as a counter
> increment/decrement in the code.
>
> Let us say obj for arr[-501] how go in todo that.
>
You are mixing concepts!
An array !== an object:
=================================
// An object is an object and not an array:
var ob = {};
// and can have any:
// ob.88 = 'hi'; // Uncaught SyntaxError: Unexpected number
ob.hi = 'hi';
ob['90'] = 'ho';
ob['-90'] = 'neg';
ob[-901] = 'neg';
alert( ob.length ); // returns: undefined
// ==================================
// An array is an array,
// but can implicitly also be used as an object:
var ar = [];
ar[3] = 'blah';
alert( ar[1] ); // returns: undefined
alert( ar.length ); // returns: 4
// array with 4 members [ 0, 1 and 2 containing undefined ]
ar[-40] = 'blob';
alert( ar.length ); // returns: 4
// Here ar[-40] the array is used as an object,
// so the array.length does not change.
====================
You could have tested this yourself, methinks.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-03-11 03:53 -0700 |
| Message-ID | <868d8999-f1b7-49bb-a33c-4e76b00ecafa@googlegroups.com> |
| In reply to | #23514 |
Den tisdagen den 11:e mars 2014 kl. 10:21:23 UTC+1 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 11 mrt 2014 in comp.lang.javascript:
>
>
>
> > 3. If i want to create an object on the fly as a counter
>
> > increment/decrement in the code.
>
> >
>
> > Let us say obj for arr[-501] how go in todo that.
>
> >
>
>
>
> You are mixing concepts!
>
>
>
> An array !== an object:
>
>
>
> =================================
>
>
>
> // An object is an object and not an array:
>
>
>
> var ob = {};
>
>
>
> // and can have any:
>
>
>
> // ob.88 = 'hi'; // Uncaught SyntaxError: Unexpected number
>
> ob.hi = 'hi';
>
> ob['90'] = 'ho';
>
> ob['-90'] = 'neg';
>
> ob[-901] = 'neg';
>
>
>
> alert( ob.length ); // returns: undefined
>
>
>
> // ==================================
>
>
>
> // An array is an array,
>
> // but can implicitly also be used as an object:
>
>
>
> var ar = [];
>
>
>
> ar[3] = 'blah';
>
> alert( ar[1] ); // returns: undefined
>
> alert( ar.length ); // returns: 4
>
>
>
> // array with 4 members [ 0, 1 and 2 containing undefined ]
>
>
>
> ar[-40] = 'blob';
>
> alert( ar.length ); // returns: 4
>
>
>
> // Here ar[-40] the array is used as an object,
>
> // so the array.length does not change.
>
>
>
> ====================
>
>
>
> You could have tested this yourself, methinks.
>
>
>
> --
>
> Evertjan.
>
> The Netherlands.
>
> (Please change the x'es to dots in my emailaddress)
Thanks for your answer Jan, as you could see i did found out that it do support negative indices.
But the core of my question was howto push/store a created object at a negative index. I know howto create an array filled with objects from index 0 but not from index -5. I know howto update objects in array.
I do not know howto extend the array in the positive negative direction by an object, is that possible.
If i found any example code i would used it.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-03-11 14:03 +0100 |
| Message-ID | <XnsA2ED8F0737DBBeejj99@194.109.133.133> |
| In reply to | #23518 |
jonas.thornvall@gmail.com wrote on 11 mrt 2014 in comp.lang.javascript:
> I wrote:
>> You could have tested this yourself, methinks.
>> --
>> Evertjan.
[please do not quote signatures on usenet]
Didn't I ask you dat before?
> Thanks for your answer Jan, as you could see i did found out that it do
> support negative indices.
1 My name is not Jan.
2 You cannot have found that out, as it is NOT TRUE.
The negative values you gave an array are not array indexes,
but property key-names, assigned by you, of the object form of that array.
*** Because they are not part of the array, they cannot be "pushed" to. ***
If you want negative keys, better assign an object, and don't pretend it to
be an array.
btw, push() adds an array member on TOP of an array!
See:
==========================
var ar = [];
ar.push('first');
alert( ar[0] ); // returns: first
ar[3] = 'blah';
alert( ar.length ); // returns: 4
ar.push('blob');
alert( ar.length ); // returns: 5
alert( ar[4] ); // returns: blob
===========================
You can also add a value [or object] at the beginning of an array,
that is at index [0],
after pushing up all other entries into the array one place up:
ar.unshift('newFirst');
alert( ar[0] ); // returns: newFirst
alert( ar[1] ); // returns: first
Still,
all properties of the array in its object form,
like:
ar['hello']
ar[-999]
will not "move",
as "move" does means NOTHING here.
> But the core of my question was howto push/store a created object at a
> negative index. I know howto create an array filled with objects from
> index 0 but not from index -5.
That is impossible. Arrays have no negative indexes, see above.
However you can use an object.
var objectMistakenlyCalledArray = {};
objectMistakenlyCalledArray[-4] = {};
> I know howto update objects in array.
Good for you, but what has this to do with your Q?
> I do not know howto extend the array in the positive negative direction
> by an object, is that possible.
Sorry, I don't understand that.
What is a "positive negative direction"?
Do you mean:
How to assign an object to another object with a negative key-value?
objectMistakenlyCalledArray[-4] = {};
> If i found any example code i would used it.
That is what is so detrimental to your way of programming.
Example codes are not for copying,
but to make you learn and understand how things work.
Then you write your own code and understand how it works,
so that you can debug it.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-03-11 07:45 -0700 |
| Message-ID | <fbd15953-edfd-4456-b4c8-7b31417ecd24@googlegroups.com> |
| In reply to | #23520 |
Den tisdagen den 11:e mars 2014 kl. 14:03:36 UTC+1 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 11 mrt 2014 in comp.lang.javascript:
>
> > I wrote:
>
> >> You could have tested this yourself, methinks.
>
> >> --
>
> >> Evertjan.
>
>
>
> [please do not quote signatures on usenet]
>
>
>
> Didn't I ask you dat before?
>
>
>
> > Thanks for your answer Jan, as you could see i did found out that it do
>
> > support negative indices.
>
>
>
> 1 My name is not Jan.
>
>
>
> 2 You cannot have found that out, as it is NOT TRUE.
Well i sure did, this for loop code will store values of index i at their respective negative indexes.
Just run it. There is no problem to store and reach values at negative indexes but i want to store objects not values.
<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>
>
> The negative values you gave an array are not array indexes,
>
> but property key-names, assigned by you, of the object form of that array.
>
Well that was my example code for objects wasn't it?
>
> *** Because they are not part of the array, they cannot be "pushed" to. ***
I can see that, so how can i store them at negative indexes, i mean if i can store a value i should be able to store an object or?
>
>
> If you want negative keys, better assign an object, and don't pretend it to
>
> be an array.
I have no idea what you mean by negative keys, i want an array that stores objects starting at the integer of my choice, yes i want to start at a negative index storing my objects.
>
>
> btw, push() adds an array member on TOP of an array!
Well actually i do understand that push put a member on top of the last one, but what i need to know and what you seem unable to answer, is can i start the array at a negative index and store a value. And i answered that one myself yes no problem in javascript, if i now could get information on howto store an object that would be great and i can go on with my programming.
> See:
>
>
>
> ==========================
>
> var ar = [];
>
> ar.push('first');
>
> alert( ar[0] ); // returns: first
Yes i understand this, but it is not what i asked.
>
>
> ar[3] = 'blah';
>
> alert( ar.length ); // returns: 4
Yes i understand this, but it is not what i asked.
I even proposed ar.push('nonsense',-i) but maybe there already is similar functionality?
If so could anyone be so kind inform me how.
You are not the only one getting irritated, i think my question is pretty straightforward, but you seem reluctant or do not know the answer.
>
>
> ar.push('blob');
>
> alert( ar.length ); // returns: 5
>
This is a none issue for me. I want add object at the other end -1. And i want to start create the object array as i showed in example above. From low to high or high to low really does not matter to me.
>
> alert( ar[4] ); // returns: blob
>
> ===========================
>
>
>
> You can also add a value [or object] at the beginning of an array,
>
> that is at index [0],
>
> after pushing up all other entries into the array one place up:
>
Well i proved to you that you can add an object to a negative index of the array and retrive it didn't i. How can i do the same with object.
>
> ar.unshift('newFirst');
>
> alert( ar[0] ); // returns: newFirst
>
> alert( ar[1] ); // returns: first
>
>
>
> Still,
>
> all properties of the array in its object form,
>
> like:
>
>
>
> ar['hello']
>
> ar[-999]
>
>
>
> will not "move",
>
> as "move" does means NOTHING here.
>
I do not understand what you are saying here.
>
>
>
> > But the core of my question was howto push/store a created object at a
>
> > negative index. I know howto create an array filled with objects from
>
> > index 0 but not from index -5.
>
>
>
> That is impossible. Arrays have no negative indexes, see above.
Well i showed you it can be done, was i just lucky??????
>
> However you can use an object.
>
>
>
> var objectMistakenlyCalledArray = {};
>
>
>
> objectMistakenlyCalledArray[-4] = {};
>
>
>
> > I know howto update objects in array.
>
>
>
> Good for you, but what has this to do with your Q?
>
>
>
> > I do not know howto extend the array in the positive negative direction
>
> > by an object, is that possible.
>
>
>
> Sorry, I don't understand that.
Well i do not see how i can be any more clear if i push i add object at end of array, how and i end at start of array -1.
> What is a "positive negative direction"?
>
>
>
> Do you mean:
>
> How to assign an object to another object with a negative key-value?
Maybe, your terminology confusing.
>
>
> objectMistakenlyCalledArray[-4] = {};
>
>
>
> > If i found any example code i would used it.
>
>
>
> That is what is so detrimental to your way of programming.
>
>
>
> Example codes are not for copying,
>
> but to make you learn and understand how things work.
>
>
>
> Then you write your own code and understand how it works,
>
> so that you can debug it.
>
>
>
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-03-11 16:24 +0100 |
| Message-ID | <XnsA2EDA6E3485F7eejj99@194.109.133.133> |
| In reply to | #23521 |
jonas.thornvall@gmail.com wrote on 11 mrt 2014 in comp.lang.javascript:
>> That is impossible. Arrays have no negative indexes, see above.
> Well i showed you it can be done, was i just lucky??????
No it cannot be done and [so] you did not show me.
You are just extremely unlucky not comprehending this yet.
The thing we call an index of an array can only be a non negative integer.
All kind of array-functions expect of an array where the elements have
numeric order within these confines.
for instance, how would you reverse a group of elements with no order,
or join them sequencially without order?
============== some array functions =========================
length returns the highest index + 1
join() joins all elements of an array into a string
lastIndexOf() searches the array for an element, starting at the end,
and returns its position
pop() Removes the last element of an array, and returns that element
push() Adds new elements to the end of an array,
and returns the new length
reverse() Reverses the order of the elements in an array
shift() Removes the first element of an array, and returns that element
slice() Selects a part of an array, and returns the new array
splice() Adds/Removes elements from an array
unshift() Adds new elements to the beginning of an array,
and returns the new length
========================================
Now an object can have keys, they are NOT called indexes:
var obj = {};
obj[1]
obj[-1]
obj[-7.555]
obj['foo']
but you cannot use any of the above functions,
as long as it is not an array too,
defined with
var obj = [];
and even then obj[1] will be the only array element,
so obj.length will be 2.
=============================================
Synopsis:
An array is not the same as an object.
The elements of an array are indicated by their index.
An array cannot have other indexes than non-negative integers.
The elements of an array have order.
This order makes most of the above functions possible.
An object's elements are indicated by a key,
this can be any string or even a number the probably will be converted to a
string.
The elements of an object have no order.
However an array is also an object, so can have elements indicated by an
index, and additionally elements that are indicated by keys.
An object not defined as an array is not an array.
=======================================
Do you still hold that an array can have negative index values?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-03-11 10:40 -0700 |
| Message-ID | <253eca00-abda-47da-8388-8a621f36fffd@googlegroups.com> |
| In reply to | #23524 |
Den tisdagen den 11:e mars 2014 kl. 16:24:20 UTC+1 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 11 mrt 2014 in comp.lang.javascript:
>
>
>
> >> That is impossible. Arrays have no negative indexes, see above.
>
> > Well i showed you it can be done, was i just lucky??????
>
>
>
> No it cannot be done and [so] you did not show me.
>
>
>
> You are just extremely unlucky not comprehending this yet.
>
>
>
> The thing we call an index of an array can only be a non negative integer.
>
>
>
> All kind of array-functions expect of an array where the elements have
>
> numeric order within these confines.
>
>
>
> for instance, how would you reverse a group of elements with no order,
>
> or join them sequencially without order?
>
>
>
> ============== some array functions =========================
>
> length returns the highest index + 1
>
>
>
> join() joins all elements of an array into a string
>
>
>
> lastIndexOf() searches the array for an element, starting at the end,
>
> and returns its position
>
>
>
> pop() Removes the last element of an array, and returns that element
>
>
>
> push() Adds new elements to the end of an array,
>
> and returns the new length
>
>
>
> reverse() Reverses the order of the elements in an array
>
>
>
> shift() Removes the first element of an array, and returns that element
>
>
>
> slice() Selects a part of an array, and returns the new array
>
>
>
> splice() Adds/Removes elements from an array
>
>
>
> unshift() Adds new elements to the beginning of an array,
>
> and returns the new length
>
> ========================================
>
>
>
> Now an object can have keys, they are NOT called indexes:
>
>
>
> var obj = {};
>
>
>
> obj[1]
>
> obj[-1]
>
> obj[-7.555]
>
> obj['foo']
>
>
>
> but you cannot use any of the above functions,
>
> as long as it is not an array too,
>
> defined with
>
>
>
> var obj = [];
>
>
>
> and even then obj[1] will be the only array element,
>
> so obj.length will be 2.
>
>
>
> =============================================
>
>
>
> Synopsis:
>
>
>
> An array is not the same as an object.
>
>
>
> The elements of an array are indicated by their index.
>
> An array cannot have other indexes than non-negative integers.
>
> The elements of an array have order.
>
> This order makes most of the above functions possible.
>
>
>
> An object's elements are indicated by a key,
>
> this can be any string or even a number the probably will be converted to a
>
> string.
>
> The elements of an object have no order.
>
>
>
> However an array is also an object, so can have elements indicated by an
>
> index, and additionally elements that are indicated by keys.
>
>
>
> An object not defined as an array is not an array.
>
>
>
> =======================================
>
>
>
> Do you still hold that an array can have negative index values?
>
>
>
>
>
Please man just run the code.
1.It is an array? I answer yes to that.
2.The numbers i put into arr represent indexes not keys? I answer yes to that.
2.It reach the values stored at the negative values of index? I answer yes to that.
By the way I run firefox.
<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>
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-03-11 10:51 -0700 |
| Message-ID | <59661127-bbd4-4eb5-b824-1b4074ccfbd9@googlegroups.com> |
| In reply to | #23530 |
Den tisdagen den 11:e mars 2014 kl. 18:40:51 UTC+1 skrev jonas.t...@gmail.com:
> Den tisdagen den 11:e mars 2014 kl. 16:24:20 UTC+1 skrev Evertjan.:
>
> > jonas.thornvall@gmail.com wrote on 11 mrt 2014 in comp.lang.javascript:
>
> >
>
> >
>
> >
>
> > >> That is impossible. Arrays have no negative indexes, see above.
>
> >
>
> > > Well i showed you it can be done, was i just lucky??????
>
> >
>
> >
>
> >
>
> > No it cannot be done and [so] you did not show me.
>
> >
>
> >
>
> >
>
> > You are just extremely unlucky not comprehending this yet.
>
> >
>
> >
>
> >
>
> > The thing we call an index of an array can only be a non negative integer.
>
> >
>
> >
>
> >
>
> > All kind of array-functions expect of an array where the elements have
>
> >
>
> > numeric order within these confines.
>
> >
>
> >
>
> >
>
> > for instance, how would you reverse a group of elements with no order,
>
> >
>
> > or join them sequencially without order?
>
> >
>
> >
>
> >
>
> > ============== some array functions =========================
>
> >
>
> > length returns the highest index + 1
>
> >
>
> >
>
> >
>
> > join() joins all elements of an array into a string
>
> >
>
> >
>
> >
>
> > lastIndexOf() searches the array for an element, starting at the end,
>
> >
>
> > and returns its position
>
> >
>
> >
>
> >
>
> > pop() Removes the last element of an array, and returns that element
>
> >
>
> >
>
> >
>
> > push() Adds new elements to the end of an array,
>
> >
>
> > and returns the new length
>
> >
>
> >
>
> >
>
> > reverse() Reverses the order of the elements in an array
>
> >
>
> >
>
> >
>
> > shift() Removes the first element of an array, and returns that element
>
> >
>
> >
>
> >
>
> > slice() Selects a part of an array, and returns the new array
>
> >
>
> >
>
> >
>
> > splice() Adds/Removes elements from an array
>
> >
>
> >
>
> >
>
> > unshift() Adds new elements to the beginning of an array,
>
> >
>
> > and returns the new length
>
> >
>
> > ========================================
>
> >
>
> >
>
> >
>
> > Now an object can have keys, they are NOT called indexes:
>
> >
>
> >
>
> >
>
> > var obj = {};
>
> >
>
> >
>
> >
>
> > obj[1]
>
> >
>
> > obj[-1]
>
> >
>
> > obj[-7.555]
>
> >
>
> > obj['foo']
>
> >
>
> >
>
> >
>
> > but you cannot use any of the above functions,
>
> >
>
> > as long as it is not an array too,
>
> >
>
> > defined with
>
> >
>
> >
>
> >
>
> > var obj = [];
>
> >
>
> >
>
> >
>
> > and even then obj[1] will be the only array element,
>
> >
>
> > so obj.length will be 2.
>
> >
>
> >
>
> >
>
> > =============================================
>
> >
>
> >
>
> >
>
> > Synopsis:
>
> >
>
> >
>
> >
>
> > An array is not the same as an object.
>
> >
>
> >
>
> >
>
> > The elements of an array are indicated by their index.
>
> >
>
> > An array cannot have other indexes than non-negative integers.
>
> >
>
> > The elements of an array have order.
>
> >
>
> > This order makes most of the above functions possible.
>
> >
>
> >
>
> >
>
> > An object's elements are indicated by a key,
>
> >
>
> > this can be any string or even a number the probably will be converted to a
>
> >
>
> > string.
>
> >
>
> > The elements of an object have no order.
>
> >
>
> >
>
> >
>
> > However an array is also an object, so can have elements indicated by an
>
> >
>
> > index, and additionally elements that are indicated by keys.
>
> >
>
> >
>
> >
>
> > An object not defined as an array is not an array.
>
> >
>
> >
>
> >
>
> > =======================================
>
> >
>
> >
>
> >
>
> > Do you still hold that an array can have negative index values?
>
> >
>
> >
>
> >
>
> >
>
> >
>
>
>
>
>
> Please man just run the code.
>
> 1.It is an array? I answer yes to that.
>
> 2.The numbers i put into arr represent indexes not keys? I answer yes to that.
>
> 2.It reach the values stored at the negative values of index? I answer yes to that.
>
>
>
> By the way I run firefox.
>
>
>
> <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>
I do not need length or any attribute of array it implicit in my code, but i do need objects or multidimensional arrays that can store strings, ***at negative indexes.***
I showed you that the array will store values at negative indexes.
So my question remains can i set also objects not only values at the negative indexes of an array.
And how do i achieve that.
[toc] | [prev] | [next] | [standalone]
| From | Christoph Michael Becker <cmbecker69@arcor.de> |
|---|---|
| Date | 2014-03-11 19:23 +0100 |
| Message-ID | <531f548b$0$6672$9b4e6d93@newsspool2.arcor-online.net> |
| In reply to | #23531 |
jonas.thornvall@gmail.com wrote:
> I do not need length or any attribute of array it implicit in my
> code, but i do need objects or multidimensional arrays that can store
> strings, ***at negative indexes.***
>
> I showed you that the array will store values at negative indexes.
No. You have shown that an array can store values in properties whose
name resembles a negative number.
> So
> my question remains can i set also objects not only values at the
> negative indexes of an array.
As there are no negative indexes[1], you can't. However, you can store
arbitrary values (for instance, object references) in properties.
> And how do i achieve that.
a[-1] = {};
[1] <http://www.ecma-international.org/ecma-262/5.1/#sec-15.4>
--
Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-03-11 15:33 -0700 |
| Message-ID | <17895397-2464-4de5-961a-8b8275ef3f69@googlegroups.com> |
| In reply to | #23536 |
Den tisdagen den 11:e mars 2014 kl. 19:23:10 UTC+1 skrev Christoph Michael Becker:
> jonas.thornvall@gmail.com wrote:
>
>
>
> > I do not need length or any attribute of array it implicit in my
>
> > code, but i do need objects or multidimensional arrays that can store
>
> > strings, ***at negative indexes.***
>
> >
>
> > I showed you that the array will store values at negative indexes.
>
>
>
> No. You have shown that an array can store values in properties whose
>
> name resembles a negative number.
Honestly i have no idea what you talk about.
You honestly try to tell me that the code does not deal with indexes?
<script type="text/javascript">
var arr=[];
for (i=10;i>=-20;i--) {arr[i]=i;}
YOU TELL ME THAT -22 NOT AN INDEX HERE?arr[-22]=-22;
for (i=10;i>=-22;i--) {document.write(arr[i],",");}
</script>
I must say that programming languages just get weirder you call it a property?
>
> > So
>
> > my question remains can i set also objects not only values at the
>
> > negative indexes of an array.
>
>
>
> As there are no negative indexes[1], you can't. However, you can store
>
> arbitrary values (for instance, object references) in properties.
>
>
>
> > And how do i achieve that.
>
>
>
> a[-1] = {};
>
>
>
> [1] <http://www.ecma-international.org/ecma-262/5.1/#sec-15.4>
>
>
>
> --
>
> Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-03-12 00:37 +0100 |
| Message-ID | <XnsA2EE666FEE3Beejj99@194.109.133.133> |
| In reply to | #23538 |
jonas.thornvall@gmail.com wrote on 11 mrt 2014 in comp.lang.javascript: > YOU TELL ME THAT -22 NOT AN INDEX HERE?arr[-22]=-22; No need to shout!!!! We are all telling you that is not an index. It is just a property you assign to the object. An array has certain methods that apply to its indexes, and those do only apply when the index is an integer that is zero or positive. ====================== If you divide a sandwich in two pieces with a fork, you could say "it is a knive, because I can divide my bread with it." However it is just a fork, and you will get into trouble when you think it is a knive, because it will not cut a piece of tough meat. If you treat programming code like a personal religious believe, don't want to look for logical explanations for the miracles you see, then you are lost to reason and beond hope. But please, do not shout on usenet! -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-03-11 16:46 -0700 |
| Message-ID | <a7137b44-7fe7-46af-80da-6920dc6e8a12@googlegroups.com> |
| In reply to | #23542 |
Den onsdagen den 12:e mars 2014 kl. 00:37:45 UTC+1 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 11 mrt 2014 in comp.lang.javascript:
>
>
>
> > YOU TELL ME THAT -22 NOT AN INDEX HERE?arr[-22]=-22;
>
>
>
> No need to shout!!!!
>
>
>
> We are all telling you that is not an index.
>
>
>
> It is just a property you assign to the object.
>
What object, isn't it an array?
Isn't this code describing an array?
<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>
>
> An array has certain methods that apply to its indexes,
>
> and those do only apply when the index is an integer that is zero or
>
> positive.
>
>
>
> ======================
>
>
>
> If you divide a sandwich in two pieces with a fork,
>
> you could say "it is a knive, because I can divide my bread with it."
>
>
>
> However it is just a fork,
>
> and you will get into trouble when you think it is a knive,
>
> because it will not cut a piece of tough meat.
>
>
>
> If you treat programming code like a personal religious believe,
>
> don't want to look for logical explanations for the miracles you see,
>
> then you are lost to reason and beond hope.
>
>
>
> But please, do not shout on usenet!
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-03-12 01:05 +0100 |
| Message-ID | <XnsA2EEB265D730eejj99@194.109.133.133> |
| In reply to | #23544 |
jonas.thornvall@gmail.com wrote on 12 mrt 2014 in comp.lang.javascript: >> It is just a property you assign to the object. >> > What object, isn't it an array? Unimportant, an array is about functioning, and you use it as an object, not as an array. If you assign a property to an object, that is not an index, the object might be an array, but it is not used as an array. As I told you, there is no sense in explaining it to you, because you believe in faith, not in aspiring for truth. The consequense is that you will stay a bad programmer, better left alone. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web