3

This code works in chrome. However, it does not print the day value when run in IE. Can anyone please answer, why this is not working in IE and how is chrome interpreting 'day'(tenDates[0].day) as key.

<html>

<body>
  <p id="demo"></p>
  <script>
    var tenDates = [];
    day = "Monday";
    date = "10/10/1976";
    tenDates.push({
      day, date
    });
    document.getElementById("demo").innerHTML =
      tenDates[0].day
  </script>
</body>

</html>
2
  • Code - <!DOCTYPE html> <html> <body> <p>JavaScript Object.</p> <p id="demo"> </p> <script> var tenDates = []; day = "Monday"; date = "10/10/1976"; tenDates.push({ day,date}); document.getElementById("demo").innerHTML = tenDates[0].day </script> </body> </html> Commented Aug 22, 2016 at 15:55
  • 2
    there is an edit button. Commented Aug 22, 2016 at 15:56

1 Answer 1

9

You are using ES6 shorthand for object literal.

{
  day, date
}

According to ES6 compatibility table IE11 and below might be having problems with this syntax.

Here are some more examples of ES2015 Object Literal extensions

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.