There is an object. How to write its values ​​in the attribute val input ? The structure of the object is as follows:

 Object { Текст: "1", Текст2: "2" } 

I am writing this code in value="[object Object]" . Tell me how to fix it?

 $.each(map, function(i,e){ $("#listProduct").val($(e) + ", "); }) 

    1 answer 1

    You $(e) is not the value in the object, but the object itself. To write the key and its value, I use this:

     $(function() { var object = {"Текст": "1", "Текст2": "2"}; for(var key in object){ $("#listProduct").val($("#listProduct").val()+key+': '+object[key]+", ") }; // Это что бы убрать запятую в конце $("#listProduct").val($("#listProduct").val().replace(/^(.+)\,\ $/, '$1')); }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" id="listProduct">