javascript - How to add an object before another object as part of a bigger object -


For my web-application, I would like to add an object before an object inside a self-defined object ... The I InsertBefore method was found, but this only applies to the DOM object, the object looks like this:

  objTemplate [0] .objEntry; ObjTemplate [1] .objEntry; & Lt; = Add objEntry here objTemplate [2] .objEntry; ObjTemplate [3] .objEntry;  

Now I would like to add a new instance of objEntry before logging into objTemplate 2. How can I do this?

Assume that objTemplate is an array You can use Array.prototype.splice :

  objTemplate.splice (2, 0, objEntry); Or, if, for whatever reason, this is not a real array (and you are using numerical index), you can also exploit the following types:  
/ P>
  Array.prototype.plice.call (objTemplate, 2, 0, objEntry);  

This will work for "array-like" items - note that your object should have a length property.


Comments