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


Groups > comp.lang.javascript > #23797 > unrolled thread

Does an array have to be reinitialised when one precreate space, if so how?

Started byjonas.thornvall@gmail.com
First post2014-04-05 14:11 -0700
Last post2014-04-05 14:24 -0700
Articles 11 — 3 participants

Back to article view | Back to comp.lang.javascript


Contents

  Does an array have to be reinitialised when one precreate space, if so how? jonas.thornvall@gmail.com - 2014-04-05 14:11 -0700
    Re: Does an array have to be reinitialised when one precreate space, if so how? jonas.thornvall@gmail.com - 2014-04-05 14:12 -0700
    Re: Does an array have to be reinitialised when one precreate space, if so how? jonas.thornvall@gmail.com - 2014-04-05 14:20 -0700
      Re: Does an array have to be reinitialised when one precreate space, if so how? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-04-06 09:27 +0200
        Re: Does an array have to be reinitialised when one precreate space, if so how? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-04-07 17:30 -0700
          Re: Does an array have to be reinitialised when one precreate space, if so how? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-04-07 23:34 -0700
          Re: Does an array have to be reinitialised when one precreate space, if so how? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-04-08 22:17 +0200
            Re: Does an array have to be reinitialised when one precreate space, if so how? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-04-08 17:01 -0700
              Re: Does an array have to be reinitialised when one precreate space, if so how? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-04-09 09:22 +0200
    Re: Does an array have to be reinitialised when one precreate space, if so how? jonas.thornvall@gmail.com - 2014-04-05 14:21 -0700
    Re: Does an array have to be reinitialised when one precreate space, if so how? jonas.thornvall@gmail.com - 2014-04-05 14:24 -0700

#23797 — Does an array have to be reinitialised when one precreate space, if so how?

Fromjonas.thornvall@gmail.com
Date2014-04-05 14:11 -0700
SubjectDoes an array have to be reinitialised when one precreate space, if so how?
Message-ID<cb9b8034-af8f-4663-b768-70a6ea1fb9c1@googlegroups.com>
I have this function that is used onload, when i call it again the scope have changed by user input and therefore the arrasize should change. But i can not see it happen in the output? Is it not possible to add objects in both ends of array extending it?

The function is called from reinitialise(); And there the scope is changed.
Function automaticly adds +-10000 to start and range for the animation and stepping. 

But changing the natural min max should, setting scope should change arraysize or?

file:///C:/Users/jonas/Desktop/prime0.993/div.html

function arraysize()
{
   
   for ( i = -scope; i <= scope; i ++ )
   { 
      arr[i] =
      {
         count : i,
         fcolor : 'black',
         rheight : 100,
         rwidth : 100,
         rcolor : 'white',
         prime : true
      }
   }
}

[toc] | [next] | [standalone]


#23798

Fromjonas.thornvall@gmail.com
Date2014-04-05 14:12 -0700
Message-ID<789f8b8b-3df4-4ab0-8e99-e0ad0320516c@googlegroups.com>
In reply to#23797
Den lördagen den 5:e april 2014 kl. 23:11:22 UTC+2 skrev jonas.t...@gmail.com:
> I have this function that is used onload, when i call it again the scope have changed by user input and therefore the arrasize should change. But i can not see it happen in the output? Is it not possible to add objects in both ends of array extending it?
> 
> 
> 
> The function is called from reinitialise(); And there the scope is changed.
> 
> Function automaticly adds +-10000 to start and range for the animation and stepping. 
> 
> 
> 
> But changing the natural min max should, setting scope should change arraysize or?
> 
> 
> 
> file:///C:/Users/jonas/Desktop/prime0.993/div.html
> 
> 
> 
> function arraysize()
> 
> {
> 
>    
> 
>    for ( i = -scope; i <= scope; i ++ )
> 
>    { 
> 
>       arr[i] =
> 
>       {
> 
>          count : i,
> 
>          fcolor : 'black',
> 
>          rheight : 100,
> 
>          rwidth : 100,
> 
>          rcolor : 'white',
> 
>          prime : true
> 
>       }
> 
>    }
> 
> }

Sorry i managed to copy adress from my desktop...
http://web.comhem.se/jonasth/prime0.993/div.html

[toc] | [prev] | [next] | [standalone]


#23799

Fromjonas.thornvall@gmail.com
Date2014-04-05 14:20 -0700
Message-ID<deb4cb27-ed25-4641-b346-3af04cfd5f38@googlegroups.com>
In reply to#23797
Den lördagen den 5:e april 2014 kl. 23:11:22 UTC+2 skrev jonas.t...@gmail.com:
> I have this function that is used onload, when i call it again the scope have changed by user input and therefore the arrasize should change. But i can not see it happen in the output? Is it not possible to add objects in both ends of array extending it?
> 
> 
> 
> The function is called from reinitialise(); And there the scope is changed.
> 
> Function automaticly adds +-10000 to start and range for the animation and stepping. 
> 
> 
> 
> But changing the natural min max should, setting scope should change arraysize or?
> 
> 
> 
> file:///C:/Users/jonas/Desktop/prime0.993/div.html
> 
> 
> 
> function arraysize()
> 
> {
> 
>    
> 
>    for ( i = -scope; i <= scope; i ++ )
> 
>    { 
> 
>       arr[i] =
> 
>       {
> 
>          count : i,
> 
>          fcolor : 'black',
> 
>          rheight : 100,
> 
>          rwidth : 100,
> 
>          rcolor : 'white',
> 
>          prime : true
> 
>       }
> 
>    }
> 
> }

Ok it is possible to add  index in the positive direction of array however extending the array in the negative direction do not work at all. Kind of weird, but on the other side someone told me negative indexes should not work at all?

[toc] | [prev] | [next] | [standalone]


#23802

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-04-06 09:27 +0200
Message-ID<XnsA3076028EC637eejj99@194.109.133.133>
In reply to#23799
jonas.thornvall@gmail.com wrote on 05 apr 2014 in comp.lang.javascript:

> Ok it is possible to add  index in the positive direction of array
> however extending the array in the negative direction do not work at
> all. Kind of weird, but on the other side someone told me negative
> indexes should not work at all? 

A javascript array always starts with index [0] and has a "length" of the 
highest set member.

Members that are not set below the top one do not exist and take no memory,
when 'asked' they return 'undefined', which they really are.

You cannot "extend an array in the negative direction" meaning that the 
index would go below [0], but you can unshift() [= shift-right] the whole 
array up while adding a new values for for the inserted indexes:

=============================
var a = [];

alert(a.length); // 0, no members being defined yet

a[0] = 'x';
a[12345] = 'y';

alert(a.length); // 12346, being from [0] to [12345]

/* free after w3schools:
The unshift() method adds new members to the beginning of an array, 
[and returns the new length].
Note: This method changes the length of an array.
Tip: To add new members at the end of an array, use the push() method.
*/

var lng = a.unshift('z');

alert('length now: ' + lng); // length now: 12347
alert(a.length); // 12347, being from [0] to [12346]

alert(a[0]); // z
alert(a[1]); // x
alert(a[2]); // undefined
alert(a[12345]); // undefined 
alert(a[12346]); // y

/* WARNING:
An array is also an object,
so you can add properties to the object.
Those properites do not affect the array behavour,
like .length and .unshift().
These added properties are just aquired properties, 
not members of that array.
*/

a['-3'] = 'qqq';
a['one'] = 'one';

alert(a.length); // 12347

/* however, 
a positive integer string is converted to a number index:
*/

a['12999'] = 'rrr';

alert(a.length); // 13000

=============================


-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#23819

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2014-04-07 17:30 -0700
Message-ID<422638e1-a922-42a7-a369-1c7ddd556248@googlegroups.com>
In reply to#23802
On Sunday, April 6, 2014 2:27:10 AM UTC-5, Evertjan. wrote:
[...]
> Members that are not set below the top one do not exist and take no memory,
> when 'asked' they return 'undefined', which they really are.
[...]

Thomas Lahn may have a better memory than I do here, but I think there are some implementation specific properties that exist in the negative indexes of arrays and/or in the arguments object

[toc] | [prev] | [next] | [standalone]


#23821

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2014-04-07 23:34 -0700
Message-ID<70dd4a82-dceb-4871-9447-8f8970c9a8e3@googlegroups.com>
In reply to#23819
On Monday, April 7, 2014 7:30:09 PM UTC-5, Michael Haufe (TNO) wrote:
> On Sunday, April 6, 2014 2:27:10 AM UTC-5, Evertjan. wrote:
> 
> [...]
> 
> > Members that are not set below the top one do not exist and take no memory,
> 
> > when 'asked' they return 'undefined', which they really are.
> 
> [...]
> 
> 
> 
> Thomas Lahn may have a better memory than I do here, but I think there are some implementation specific properties that exist in the negative indexes of arrays and/or in the arguments object

Found what I was recalling: <http://webreflection.blogspot.com/2009/06/javascript-arguments-weridness.html>

[toc] | [prev] | [next] | [standalone]


#23823

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-04-08 22:17 +0200
Message-ID<XnsA309E2AF0E50Eeejj99@194.109.133.133>
In reply to#23819
"Michael Haufe (TNO)" <tno@thenewobjective.com> wrote on 08 apr 2014 in
comp.lang.javascript: 

> On Sunday, April 6, 2014 2:27:10 AM UTC-5, Evertjan. wrote:
> [...]
>> Members that are not set below the top one do not exist and take no
>> memory, when 'asked' they return 'undefined', which they really are.
> [...]
> 
> Thomas Lahn may have a better memory than I do here, but I think there
> are some implementation specific properties that exist in the negative
> indexes of arrays and/or in the arguments object 

Javascript arrays have NO negative indexes.

This is quite independent of your memory of even PE's.

However you could add properties to the object identity of an array,
that mimicks negative indexes, like you could do this with non integer 
values.

var a = [];
a[1.2] = '??';
alert( a.length );
alert( a[1.2] );
// Here 1.2 clearly is NOT an index, but just a property.

a[-1.2] = '????';
alert( a.length );
alert( a[-1.2] );
// Here -1.2 clearly is NOT an index, but just a property.

a[-7] = '??????';
alert( a.length );
alert( a[-7] );
// So -7 too is NOT an index, just a property.

// Calling this an index is not only incorrect, 
// but also leads to incorrect assumptions 
// about the array functions like:

//// length, concat(), indexOf(), join(), lastIndexOf(),
//// pop(), push(), reverse(), shift(), slice(), 
//// sort(), splice(), unshift()

var b = [];
b[-7] = 'x';
b[3] = 'y';
b[7] = 'z';

alert(b.indexOf('y')); // 3
alert(b.indexOf('x')); // -1 !!

alert(b.concat()); // ,,,y,,,,z
alert(b.reverse()); // z,,,,y,,,


-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#23825

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2014-04-08 17:01 -0700
Message-ID<4db2e724-a50a-4c36-881a-0fc7ed1fb23b@googlegroups.com>
In reply to#23823
On Tuesday, April 8, 2014 3:17:02 PM UTC-5, Evertjan. wrote:
> "Michael Haufe (TNO)" <...> wrote on 08 apr 2014 in
> comp.lang.javascript: 
> > On Sunday, April 6, 2014 2:27:10 AM UTC-5, Evertjan. wrote:
> > [...]
> >> Members that are not set below the top one do not exist and take no
> >> memory, when 'asked' they return 'undefined', which they really are.
> 
> > [...]
> 
> > 
> > Thomas Lahn may have a better memory than I do here, but I think there
> > are some implementation specific properties that exist in the negative
> > indexes of arrays and/or in the arguments object 
> 
> Javascript arrays have NO negative indexes.
>  
> This is quite independent of your memory of even PE's.
>
> However you could add properties to the object identity of an array,
> that mimicks negative indexes, like you could do this with non integer 
> values.
 [...]

NSS, that was what I meant even if the wording was clumsy. I should have used scare quotes.

[toc] | [prev] | [next] | [standalone]


#23826

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-04-09 09:22 +0200
Message-ID<XnsA30A5F4A46CBEeejj99@194.109.133.133>
In reply to#23825
"Michael Haufe (TNO)" <tno@thenewobjective.com> wrote on 09 apr 2014 in
comp.lang.javascript: 

>> > 
>> > Thomas Lahn may have a better memory than I do here, but I think
>> > there are some implementation specific properties that exist in the
>> > negative indexes of arrays and/or in the arguments object 
>> 
>> Javascript arrays have NO negative indexes.
>>  
>> This is quite independent of your memory of even PE's.
>>
>> However you could add properties to the object identity of an array,
>> that mimicks negative indexes, like you could do this with non integer 
>> values.
>  [...]
> 
> NSS, that was what I meant even if the wording was clumsy. I should have
> used scare quotes. 

Scare goats or square quotes?
<https://youtu.be/lmJDDC0e0bw>

With "However, you could" I ment "However, you shouldn't",
at least not visibly on this NG, 
where newbees use code without understanding the same.

Because they and yourself [non-specific you] are bound to use one of the 
functions you [specific you] skipped, later. 

It is much safer to use an offset 
pushing all index key values in the positive realm,
or marginally better
not defining an array at all, using 'just' an object:

var a = {};
a[3] = 7;
a[-6] = 'hi'; 
alert(a[3]); // 7
alert(a[-6]); // hi
alert(a.length); // undefined

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#23800

Fromjonas.thornvall@gmail.com
Date2014-04-05 14:21 -0700
Message-ID<2f42f5be-de7c-4433-a60e-e6c8c4ab8869@googlegroups.com>
In reply to#23797
Den lördagen den 5:e april 2014 kl. 23:11:22 UTC+2 skrev jonas.t...@gmail.com:
> I have this function that is used onload, when i call it again the scope have changed by user input and therefore the arrasize should change. But i can not see it happen in the output? Is it not possible to add objects in both ends of array extending it?
> 
> 
> 
> The function is called from reinitialise(); And there the scope is changed.
> 
> Function automaticly adds +-10000 to start and range for the animation and stepping. 
> 
> 
> 
> But changing the natural min max should, setting scope should change arraysize or?
> 
> 
> 
> file:///C:/Users/jonas/Desktop/prime0.993/div.html
> 
> 
> 
> function arraysize()
> 
> {
> 
>    
> 
>    for ( i = -scope; i <= scope; i ++ )
> 
>    { 
> 
>       arr[i] =
> 
>       {
> 
>          count : i,
> 
>          fcolor : 'black',
> 
>          rheight : 100,
> 
>          rwidth : 100,
> 
>          rcolor : 'white',
> 
>          prime : true
> 
>       }
> 
>    }
> 
> }

Maybe there is a way to reset the whole array?

[toc] | [prev] | [next] | [standalone]


#23801

Fromjonas.thornvall@gmail.com
Date2014-04-05 14:24 -0700
Message-ID<fdc04c2b-d217-4bf6-a2e7-d357eec24443@googlegroups.com>
In reply to#23797
Den lördagen den 5:e april 2014 kl. 23:11:22 UTC+2 skrev jonas.t...@gmail.com:
> I have this function that is used onload, when i call it again the scope have changed by user input and therefore the arrasize should change. But i can not see it happen in the output? Is it not possible to add objects in both ends of array extending it?
> 
> 
> 
> The function is called from reinitialise(); And there the scope is changed.
> 
> Function automaticly adds +-10000 to start and range for the animation and stepping. 
> 
> 
> 
> But changing the natural min max should, setting scope should change arraysize or?
> 
> 
> 
> file:///C:/Users/jonas/Desktop/prime0.993/div.html
> 
> 
> 
> function arraysize()
> 
> {
> 
>    
> 
>    for ( i = -scope; i <= scope; i ++ )
> 
>    { 
> 
>       arr[i] =
> 
>       {
> 
>          count : i,
> 
>          fcolor : 'black',
> 
>          rheight : 100,
> 
>          rwidth : 100,
> 
>          rcolor : 'white',
> 
>          prime : true
> 
>       }
> 
>    }
> 
> }

Forget it it was my changes that caused the problems fixed.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web