Possible Duplicate:
how to empty an array in JavaScript
var jsonParent = [];
This is my jsonArray I am pushing some elements in the array, but now I want to empty this array and remove all elements from it.
In terms of saving memory and references use
jsonParent.length = 0
If there are no other references to the same array then the easiest thing to do is just assign jsonParent
to a new empty array:
jsonParent = [];
But if your code has other references to the same array instance then that would leave those other references with the original (populated) array and jsonParent
with a different (empty) array. So if that is possible in your situation and you want to empty the actual array instance that you already have you can do:
jsonParent.length = 0;
// or if you like ugly:
jsonParent.splice(0, jsonParent.length);
(Note also that you are not using JSON here in any way. It's not JSON if it's not a string.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With