Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 512
Younis Ar M Avatar asked Jul 25 '26 09:07

Younis Ar M


1 Answers

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

like image 135
oKonyk Avatar answered Jul 26 '26 23:07

oKonyk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!