Uncaught TypeError: Cannot use 'in' operator to search for 'length' in Uncaught TypeError: Cannot use 'in' operator to search for 'length' in javascript javascript

Uncaught TypeError: Cannot use 'in' operator to search for 'length' in


The in operator only works on objects. You are using it on a string. Make sure your value is an object before you using $.each. In this specific case, you have to parse the JSON:

$.each(JSON.parse(myData), ...);


maybe you forget to add parameter dataType:'json' in your $.ajax

$.ajax({   type: "POST",   dataType: "json",   url: url,   data: { get_member: id },   success: function( response )    {      //some action here   },   error: function( error )   {     alert( error );   }});


The only solution that worked for me and $.each was definitely causing the error. so i used for loop and it's not throwing error anymore.

Example code

     $.ajax({            type: 'GET',            url: 'https://example.com/api',            data: { get_param: 'value' },            success: function (data) {                for (var i = 0; i < data.length; ++i) {                    console.log(data[i].NameGerman);                }            }        });