JavaScript: how to define an "object"

I use a very handy JSLint tool to ensure that my javascript is rigorous.

I have the following code that is tagged with JSLint:

var my_obj = new Object();   // <-- JSLint states "Use the object literal notation {}."
var numKP = 1;

while (query.indexOf('&') > -1) {
    keypairs[numKP] = query.substring(0,query.indexOf('&'));
    query = query.substring((query.indexOf('&')) + 1);
    numKP++;
}

keypairs[numKP] = query;

for (i in keypairs) {
    my_obj[keypairs] = keypairs[i];
}

How do I fix the code above to make its JavaScript "strong" (pass JSLint authentication)?

+3
source share
2 answers

Literally, as the message says, in fact:

var my_obj = {};

, , , , JSLint. ( , , , , , . Edit: ECMAScript, 11.1.5, new Object(). , , .)

+4

 var my_obj = {};

{} - javascript .

+1

Source: https://habr.com/ru/post/1774543/


All Articles