3 Replies - 436 Views - Last Post: 30 January 2013 - 07:45 AM

#1 lse123  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 68
  • Joined: 26-May 08

what if are both objects, i use the same

Posted 29 January 2013 - 01:40 AM

stickyObjects.push(stickyObjForFile); // stickyObjForFile is obj, stickyObjects is array

what if are both objects, i use the same "push()"?
Is This A Good Question/Topic? 0
  • +

Replies To: what if are both objects, i use the same

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3560
  • View blog
  • Posts: 10,356
  • Joined: 08-June 10

Re: what if are both objects, i use the same

Posted 29 January 2013 - 03:09 AM

that depends on the methods provided by the stickyObjects object. if there is a push() method and it does what you want, then that will do.
as a rule of thumb, if stickyObjects is a plain object (i.e. if stickyObjects.toString() returns "[object Object]") there will be no (default) push() method.
Was This Post Helpful? 0
  • +
  • -

#3 lse123  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 68
  • Joined: 26-May 08

Re: what if are both objects, i use the same

Posted 30 January 2013 - 01:36 AM

i want to insert - push - a list of objects of same kind in another object... since the final i want to stringify to store in local storage or txt file i want this to be obj not array?

well what do to push one by one in a for loop objs to another obj(the latter acts like an array)...well?
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3560
  • View blog
  • Posts: 10,356
  • Joined: 08-June 10

Re: what if are both objects, i use the same

Posted 30 January 2013 - 07:45 AM

View Postlse123, on 30 January 2013 - 09:36 AM, said:

i want to insert - push - a list of objects of same kind in another object... since the final i want to stringify to store in local storage or txt file i want this to be obj not array?

well, you could do some kind of "associative array"/hash map, which is just a couple of key-value pairs. though I donít see any advantage over an Array (which is, btw., also an object). in contrast, by not using an Array you loose all the advantages an Array has (push, pop, iteration, loops, mutations)

View Postlse123, on 30 January 2013 - 09:36 AM, said:

well what do to push one by one in a for loop objs to another obj(the latter acts like an array)...well?

if you want an Array-like object, why not using an Array? itís not that you couldnít stringify an Array for local storage Ö
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1