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


Groups > comp.lang.javascript > #23514

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>
Date 2014-03-11 10:21 +0100
Message-ID <XnsA2ED695A14973eejj99@194.109.133.133> (permalink)

Show all headers | View raw


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)

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