2017-06-23 32 views
-4

我需要一些幫助與此代碼。我收到一個意外的令牌錯誤。使用推送方法將兩個變量添加到空數組

SyntaxError: Unexpected token, expected ; (8:11)

  1. Declare two variables, a string and an integer named fullName and birthYear, and set them equal to "Linus Torvalds" and 1969.
var fullName="Linus Torvalds"; 
var birthYear= 1969; 
  1. Declare an empty array called myArray.
var myArray=[]; 
  1. Add the variables from #1 (fullName and birthYear) to myArray using the push method. Print myArray to the console.
myArray.push(fullName, birthYear); 
console.log(myArray); 
+0

你的代碼是什麼? – cpugourou

+0

該代碼工作得很好。你的環境是什麼?瀏覽器(哪個)? Node.js的? – randomir

+0

請提供堆棧跟蹤。 '意外的令牌錯誤'可能意味着任何事情。 –

回答

0

試試這個

myArray.push({ 
    fullName : fullName, 
    birthYear : birthYear 
}); 
相關問題