How can I find out the index number of an object that I pushed into an array?

First off, I’ll assume the gridData is an array, not an object as you’ve shown in your sample code because an object doesn’t have a .push() method, but an array does.

Use .length - 1 as the index to the last item you pushed onto the array or save the returned value from .push() which is the new length of the array. This will be the index of the element that you just pushed onto the array and will be valid until you modify the array before that index (adding or removing items before that index).

var testRowIndex = gridData.push(TestRow) - 1;
// then you can access that item like this 
var item = gridData[testRowIndex];

Though, this doesn’t make a whole lot of sense since you already have the data right in TestRow. As usual, if you describe what problem you’re really trying to solve, we can probably provide more useful answers.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)