I am trying to empty JavaScript array which is declared globally. Here is my code-->
var arr = [];
var store = [];
var result_count = '';
var result = '';
var store_count = '';
$('select').on('change', function() {
arr.push(this.value);
var record_count = arr.length;
for (var i = 0; i < record_count; i++) {
store[i] = arr[i].split("-");
}
store_count = store.length;
});
$("#save_seting_permission").click(function() {
$.ajax({
type: 'post',
dataType: 'JSON',
url: base_url + "admin/permission_submit",
data: {
result: JSON.stringify(store),
result_count: store_count
},
success: function(result) {
/* while(store.length > 0)
{
store.pop();
} */
store.length = 0;
//console.log(store);
},
});
});
array named store declared globally. I am pushing values on change event of drop down, & sending values to database in ajax submission & clearing(emptying) array. Next time again when I am pushing values to array, old values are still there in array(though I have cleared it in ajax success).