0

Hy,

I have an angular application. There is a case where i get an object by click on it and this object is in an array. So by example i have: newObject: {object3} arrayOfObjects: [{object1}, {object2}, ....]

So when i select {object2} i want to put newObject before or after {object2}

I tried with indexOf() to get the index of the object to go trough but indexOf() seems not to be working in this case.

I have a solution to get the parent of selected object so now i only need to find a way to put my new object in position. Maybe there is an angular way for this? Or something else? underscore maybe?

Bert Duyck
  • 13
  • 3

1 Answers1

0

Adding as answer as I dont have enough points to comment.

Hi Bert,

Are you looking for something like this? How to insert an item into an array at a specific index?

Community
  • 1
  • 1
SamD
  • 120
  • 1
  • 10
  • No, because i dont know the index of my object in the array. array.indexOf(object) also doesnt work because indexOf only seems to be working on values in an array. – Bert Duyck May 02 '16 at 20:50