Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #23521
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2014-03-11 07:45 -0700 |
| References | <b766bb8c-c9a9-4914-bf16-fe342ef06930@googlegroups.com> <XnsA2ED695A14973eejj99@194.109.133.133> <868d8999-f1b7-49bb-a33c-4e76b00ecafa@googlegroups.com> <XnsA2ED8F0737DBBeejj99@194.109.133.133> |
| Message-ID | <fbd15953-edfd-4456-b4c8-7b31417ecd24@googlegroups.com> (permalink) |
| Subject | Re: arr.push(obj); |
| From | jonas.thornvall@gmail.com |
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.
>
>
>
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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