我正在尝试将动态创建的对象传递到 JavaScript 中的数组中。对象通过了,但是当我尝试检索对象内部的数据时,它就消失了。控制台记录round[object, object]。我怎样才能使这项工作?
这是我的代码:
function roundList(myRounds){
var savedRounds = [];
savedRounds.push(myRounds);
console.log("this is savedRounds " + savedRounds);
};
function round(course,tee,slope,rating,score){
this.course=course;
this.tee=tee;
this.slope=slope;
this.rating=rating;
this.score=score;
}
function makeRound(){
var newCourse = document.getElementById('course').value
var newTee = document.getElementById('tee').value
var newSlope = document.getElementById('slope').value
var newRating = document.getElementById('rating').value
var newScore = document.getElementById('score').value
var newDate = document.getElementById('date').value
var newRound = new round(newCourse,newTee,newSlope,newRating,newScore);
roundList(newRound);
}