[removed] Can a comma occur after the last set of values in an array?

后端 未结 3 1107
抹茶落季
抹茶落季 2020-12-03 10:03

I am wondering if a comma trailing an array in javascript is valid?

var settings = {
    \'foo\'  : oof,
    \'bar\' : rab,
};

vs



        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 10:36

    With regards to object literals at least (the question's title mentions array, but the example is an object literal) it depends on where your js is running. Trailing commas in object literals are valid in ES5. Although trailing commas can cause problems on the web (in IE) most minifiers will remove them anyway.

    http://www.2ality.com/2011/06/object-literal-comma.html

    http://dontkry.com/posts/code/trailing-commas.html

提交回复
热议问题