我正在尝试区分两个对象
previousChart: {BWP: 1, ZAR: 1.3, USD: 0.09324, number: 1},
currentChart: {BWP: 1, ZAR: 1.35, USD: 0.01, number: 2}
期望的答案是:
newObject ={BWP: 0, ZAR: 0.05, USD: 0.08324, number: -1}
请不要问我做了什么,因为这是最后一个阶段,因为这是我的代码的最后一部分,如果你有兴趣知道我在这里做了什么,那就是:
rates = [
{BWP: 1, ZAR: 1.3, USD: 0.09324, number: 1},
{BWP: 1, ZAR: 1.35, USD: 0.01, number: 2},
{BWP: 1, ZAR: 1.3456, USD: 0.09234, number: 3},
{BWP: 1, ZAR: 1.27894, USD: 0.06788, number: 4}
]
newRate = [];
for(let i in rates){
if( i - 1 === -1 ){
previousChart = rates[0];
}else{
previousChart = rates[i - 1];
}
let currentChart = rates[i];
}