我正在寻找一种方法将这两个对象组合成一个函数或减少我的行数的东西。
var fsInfo1 = { name: 'Joshua Velez', address:{ street: '94-1411 Kulewa Loop ', city: 'Waipahu, ', state: 'HI' }, gpa: [3.3,4.0,2.8] } var fsInfo2= { name: 'John Doe', address:{ street: 'Some Street ', city: 'Wahiawa, ', state: 'HI' }, gpa: [3.4,3.6,3.1] }
console.log("名称:" + fsInfo1.name)
console.log("地址:" + fsInfo1.address['street'] + fsInfo1.address['city'] + fsInfo1.address['state']) console.log("GPA:" + fsInfo1.gpa[0 ],fsInfo1.gpa[1],fsInfo1.gpa[2])
console.log("名称:" + fsInfo2.name)
console.log("地址:" + fsInfo2.address['street'] + fsInfo2.address['city'] + > fsInfo2.address['state']) console.log("GPA:" + fsInfo2.gpa[ 0],fsInfo2.gpa[1],fsInfo2.gpa[2])