Finding duplicate keys in JavaScript object

前端 未结 1 1428
温柔的废话
温柔的废话 2020-12-21 10:55

I have a file whose sole purpose is to provide an enormous collection of key/value pairs in an object. It looks something like this:

var myobj = {
   some_ke         


        
相关标签:
1条回答
  • 2020-12-21 11:31

    Add "use strict"; to the top of your file. Example usage:

    (function() {
      "use strict";
      // Throws a syntax error
      var a = {
        b: 5,
        b: 6
      };
    })();
    

    Edit: This answer is no longer strictly up to date due to ES6 computed property values. If you want, you can write your object as a JSON object (if that's possible) and put it through http://www.jslint.com/, which will check for duplicate keys. See as well: "use strict"; now allows duplicated properties?

    0 讨论(0)
提交回复
热议问题