The question seems to be simple, but something is googling and having tried different methods and because of poor knowledge js is completely confused. There is a notation:

{action:"someAction",data:info} 

where info needs to be filled in the loop with key: value elements. How to express it in notation? How to attach elements like in php?

  array["key"]=value 

ps Connected JSON2.js

UPD I will clarify the question of how to dynamically add a property to a property whose name is contained in a variable that is constantly changing in a loop?

    2 answers 2

    Either it is an array, and then the key concept : there is no value in the usual sense:

     res = [ el1, el2, el3 ]; 

    And then add this:

     res.push( el4 ); //На крайний случай, но лучше не велосипедничать res[ res.length ] = el4; 

    Or it is an object:

     res = { key1: val1, key2: val2 }; 

    And add this:

     res[ key4 ] = val4; 

      I apologize all the question is really very stupid, the usual ignorance of syntax, but suddenly someone will be useful:

       var info=Object(); info[key]=value; //Добавление свойств объекта аналогично ассоциативному массиву в php {action:"someAction",data:JSON.stringify(info)} //Здесь используем stringify для конвертации объекта в json 
      • instead of Object use {} - Zowie
      • MM what's the difference? - culebre
      • In the professionalism of the code ... Yes, and if you are already using object, write new Object() , then there is at least some meaning to it (although you definitely don’t need it ^^) - Zowie