Getting a “TypeError: invalid ‘in’ operand a” within WordPress

So I am getting a TypeError: invalid ‘in’ operand a error within WordPress (not sure if that is relevant to it) and I’m not really sure what’s wrong with code.

Here is the code in question:

Read More
e_jsonObj = [];            
$.each(the_wpcc_posts, function(i, the_wpcc_post) {
    var e_post_id = the_wpcc_post[i].ID;
    var e_title = the_wpcc_post[i].post_title;
    var e_start = the_wpcc_post[i].post_date_gmt;

    e_item = {}
    e_item ["id"] = e_post_id;
    e_item ["title"] = e_title;
    e_item ["start"] = e_start;

    console.log(e_item);

    e_jsonObj.push(e_item);         

});

Any help here is much appreciated.

Related posts

1 comment

  1. Try it this way by parsing the data before each loop.
    It seems like you are trying to iterate over a string, that is causing this error.

    e_jsonObj = [];
    data = $.parseJSON(the_wpcc_posts);  // parsing data          
    $.each(data, function(i, the_wpcc_post) {
        var e_post_id = the_wpcc_post[i].ID;
        var e_title = the_wpcc_post[i].post_title;
        var e_start = the_wpcc_post[i].post_date_gmt;
    
        e_item = {}
        e_item ["id"] = e_post_id;
        e_item ["title"] = e_title;
        e_item ["start"] = e_start;
    
        console.log(e_item);
    
        e_jsonObj.push(e_item);         
    
    });
    

Comments are closed.