javascript - Get back initial content of array -
i have function wich deletes elements array,is there way initial content of array when there no elements in ? know have use
if(array.length=0){ }
but beats me put inside curly braces.i've tried create array duplicate first one,and after implementing function assigning empty array duplicated one,but didn't work
if want copy of array need called deep copy.
var = [11,22,33,44,55,66,77,88,99]; var a_copy = a; var a_backup = []; console.log("original length = " + a.length) for(var = 0;i<a.length;i++){ a_backup[i] = a[i]; } for(var = 0;i<a.length;i++){ a[i] = undefined; } console.log("original = " + a.join(",")) console.log("copy = " + a_copy.join(",")) console.log("backup = " + a_backup.join(",")) console.log("original length = " + a.length) for(var = 0;i<a_backup.length;i++){ a[i] = a_backup[i]; } console.log("restored = " + a.join(","))
it depends on how deleted entries. if did did length stays same there other methods change length of array itself, need check that.
Comments
Post a Comment