如何从其他字典更新一个字典中的键

时间:2017-05-15 09:05:14

标签: javascript dictionary

dict1中存在的以下键值将在dict2中更新,其中包含与开头相同数量的键值对。

var dict1={name:"alex",1:"24",office:"germany"} //original dictionary
var dict2=dict1; //copy of original dict1

funct(dict1){
    //code that is used to change the values of dict1 to the following values.
}
console.log(dict1); //dict1:{0:"alex",undefined:24,2:"germany"}

funct(dict1,dict2){
    let {undefined:val} = dict1; //deleting the undefined key-value pair from dict1
    delete dict1["undefined"];
    console.log(dict1);     //dict1:{0:"alex",2:"germany"}
    //how can i update the dict2 with the values present in the dict1?
    //the final dict2 should have following values:
    console.log(dict2); //dict2={0:"alex",1:"24",2:"germany"}
}

0 个答案:

没有答案
相关问题