Javascript 多个Array.sort后数组顺序已更改

Javascript 多个Array.sort后数组顺序已更改,javascript,arrays,sorting,variables,Javascript,Arrays,Sorting,Variables,我有一个对数组排序的代码 const timeSorted = wheater.list.sort((z,x)=> { return z.dt- x.dt }) console.log(timeSorted) 我得到的输出已排序 但是如果我再加上一种像这样的 const timeSorted = wheater.list.sort((z,x)=> { return z.dt- x.dt }) const tempSorted = wheater.list.sort(

我有一个对数组排序的代码

const timeSorted = wheater.list.sort((z,x)=>
{
    return z.dt- x.dt
})
console.log(timeSorted)
我得到的输出已排序
但是如果我再加上一种像这样的

const timeSorted = wheater.list.sort((z,x)=>
{
    return z.dt- x.dt
})
const tempSorted = wheater.list.sort((a,b)=>
{
    return a.main.temp - b.main.temp
})
console.log(timeSorted)
常量时间排序变为临时排序

我如何解决这个问题?

数组已排序到位

为了不改变它,您需要使用
oldArray.slice()
创建上一个数组的副本

数组已按位置排序

为了不改变它,您需要使用
oldArray.slice()
创建上一个数组的副本


请同时添加数组。@NinaScholz数组来自api。太长了,不是全部,只有两行具有上述属性。更多信息:请同时添加数组。@NinaScholz数组来自api。太长了,不是全部,只有两行具有上述属性。更多:和
const tempSorted = wheater.list.slice().sort((a,b)=>
{
    return a.main.temp - b.main.temp
})