Error [object Object] get value of ids(loop to remove class

In example below i have 3 courses for employee Michel

I have 3 courses per employee
c# removebutton
sql removebutton
java removebutton
i need to remove sql and java and store values in ids variable
i do it but when check variable ids it give me error
i check value of ids it give me error

local host 3642 says [object Object]
actually i need to loop through remove class then remove courses have remove class then store values in ids variable
but when check it give me error [object Object]
why and how to solve this error

 <script>  
        $(function () {  
              
            var index = 0;  
             
            $("#tb").on("click", ".r", function () {  
               
                  $(this).parent().parent().hide();  
                   
                  $(this).parent().prev().prev().find("input").addClass("remove");  
                
                    
             });  
            var ids = {};  
            var i = 0;  
            $(".remove").each(function () {  
                ids[i] = $(this).val();  
                i++;  
            });  
            $('#removeid').click(function () {  
                alert(ids);  
            });  
// to get values of courses when page loaded  
            $.ajax({  
                url: "/Employeedata/getcoursesbyempid",  
                data:{x:$("#hid").val()},  
                success: function (res) {  
                    $.each(res, function (i, e) {  
  
  
  
                        $("#tb").append("<tr><td><input type = 'hidden' name='empcourses[" + index + "].CourseId' value='" + e.Id + "'/></td><td>" + e.CourseName + "</td><td><input type='button' value='remove' class='r'</td></tr>")  
  
  
  
                        index++;  
                    });  
                }  
  
            })  
        });  
    </script>  
</head>  
<body>  
    <div>  
        
                <input type="hidden" value="@ViewBag.hid" id="hid" />  
                
                 
                <input type="submit" value="save" />  
                <input type="submit" value="getvalue" id="removeid" />  
  
            </div>  
            <table id="tb">  
  
            </table>  
        }

This is not an error. It is what JS shows when you use object as argument for alert().
If you want to see what’s inside that object, the most simple solution would be to use console.log() instead of alert():

console.log(ids);

This method will print object contents in the browser’s console. To open the console press F12 (or Ctrl+Shift+I), then select “Console” tab.

1 Like

To use alert you can do the following:-
alert(JSON.stringify(ids));

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.