Younis Ar M
Younis Ar M

Reputation: 941

javascript object{key, value}

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>

Upvotes: 3

Views: 60

Answers (1)

oKonyk
oKonyk

Reputation: 1476

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

Upvotes: 9

Related Questions