I made a code that removes '-1' in array, but I don't want to modify original one.
following is that one.
var original = [ 1, 2, 3, 4, -1, -1 ];
var temp = original;
for ( var i = ( temp.length - 1 ); i >= 0; i-- ) {
if ( temp[j] == -1 ) {
temp.splice( i, 1 );
}
after script executed. original is [ 1, 2, 3, 4 ] and temp also is [ 1, 2, 3, 4 ]
both original and temp are modified!
why is it?