How to clear the jsonArray in javascript
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.
在节省内存和参考使用方面
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.)
just assign
jsonParent = []
again when you want to remove all elements
链接地址: http://www.djcxy.com/p/23944.html上一篇: 清除Javascript数组中的对象