Strange error "Null or not object" in IE

IE reports: Error: "parent_name" is null or not an object

for line 3 in the code below:

populate(default_parent, jQuery('#categoryParent').get(0), jQuery.map(categories, function (cat) {
        return {
            name: cat.parent_name,
            value: cat.parent_slug
        }
    }));

Removing the above code snippet, the error disappears, so definitely the source of the error is here.

The categories object is similar:

var categories = [
    { parent_slug:"real_estate", parent_name:"Ακίνητα", childs: [
                        {child_slug: "homes", child_name: "Σπίτια"},
                        {child_slug: "apartments", child_name: "Διαμερίσματα"},                                     ]},
    { parent_slug:"jobs", parent_name:"Εργασία", childs: [
                        {child_slug: "restaurant_food_service_jobs", child_name: "Εστιατόρια"},
...];

Everything works well in FF, Chrome, etc.

+3
source share
1 answer

Assuming this is complete code, I think the error is probably related to the syntax you use to install categories. You have arrays and comma separated objects like

var myArray = ['item1', 'item2',];
var myObject = {foo: 'item1', bar: 'item2',}

This is accepted by all browsers except IE. Try again with the trailing commas.

+4
source

Source: https://habr.com/ru/post/1784133/


All Articles