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


Groups > comp.lang.javascript > #23520

Re: arr.push(obj);

Newsgroups comp.lang.javascript
Subject Re: arr.push(obj);
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <b766bb8c-c9a9-4914-bf16-fe342ef06930@googlegroups.com> <XnsA2ED695A14973eejj99@194.109.133.133> <868d8999-f1b7-49bb-a33c-4e76b00ecafa@googlegroups.com>
Date 2014-03-11 14:03 +0100
Message-ID <XnsA2ED8F0737DBBeejj99@194.109.133.133> (permalink)

Show all headers | View raw


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)

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