I've searched other threads and I couldn't find a working solution to my problem. I tried slice() for the array but no luck. I've got a array, first I create a copy of the original array and after a few second I overwrite one value [0][1]=555. And this affects my copy/original array, the value 1000 gets overwritten with 555. Any ideas on how to overcome this? I need to compare the two tables after the value gets changed. Here is my javascript code:
let intialstationtablevalues = [
["station name 1",75,100,100,100,100,100,100,0,100,100,100,100,1],
["station name 2",200,220,100,100,100,100,100,2,100,100,100,100,2],
["station name 3",300,110,100,100,100,100,100,0,100,100,100,760,3],
["station name 4",400,100,109,100,100,100,100,3,100,100,100,100,4],
["station name 5",500,100,100,100,100,100,100,0,100,100,100,100,5],
["station name 6",600,130,134,100,100,100,100,2,100,100,100,340,6],
["station name 7",700,100,100,100,100,100,100,0,100,100,100,100,7],
["station name 8",800,200,340,100,100,100,100,5,100,100,100,10,8],
["station name 9",900,100,100,100,100,100,100,0,100,100,100,6,9],
["station name 10",1000,100,900,100,100,100,100,2,100,100,100,100,10],
];
let old = []
let copy = []
setInterval(read,2000)
setTimeout(changevalue,10000)
function changevalue(){
console.log("value changed")
intialstationtablevalues[0][1]=555;
}
function read(){
if(copy==""){
copy = intialstationtablevalues.slice()
}
sortnow = intialstationtablevalues.sort(function(a,b){
return b[1]-a[1];
})
console.log("sortnow",sortnow)
if(old==""){
copy.forEach(function(item,index){
old.push(item)
})
old.sort(function(a,b){
return b[1]-a[1];
})
}
console.log("old",old)
}