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>
Raktim Biswas
4,1055 gold badges30 silver badges34 bronze badges
asked Aug 22, 2016 at 15:53
Younis Ar M
9397 silver badges16 bronze badges
-
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>Younis Ar M– Younis Ar M2016年08月22日 15:55:04 +00:00Commented Aug 22, 2016 at 15:55
-
2there is an edit button.ASDFGerte– ASDFGerte2016年08月22日 15:56:46 +00:00Commented Aug 22, 2016 at 15:56
1 Answer 1
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
lang-js