2017-06-23 2 views
-4

J'ai besoin d'aide avec ce code. Je reçois une erreur de jeton inattendue.Ajout de deux variables pour vider un tableau en utilisant la méthode push

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

Quel est votre code? – cpugourou

+0

Ce code fonctionne très bien. Quel est ton environnement? Navigateur (lequel)? Node.js? – randomir

+0

Fournissez la trace de la pile, s'il vous plaît. 'Erreur de jeton inattendue' peut signifier n'importe quoi. –

Répondre

0

Essayez cette

myArray.push({ 
    fullName : fullName, 
    birthYear : birthYear 
});