With that row
var element = {};
you define element
to be a plain object. The native JavaScript object has no push()
method. To add new items to a plain object use this syntax:
element[ yourKey ] = yourValue;
On the other hand you could define element
as an array using
var element = [];
Then you can add elements using push()
.