Javascript Array Items Loaded With Wrong Index -


i'm using arrays static types used in project. @ starting of js file defining array items below.

var reports = (function() {      var claimtraceprocesses = [];    claimtraceprocesses.push({      id: 9,      name: "non-insurance",      nametr: "sigorta dışı"    });    claimtraceprocesses.push({      id: 100000001,      name: "in-house",      nametr: "kurum İçi"    });    claimtraceprocesses.push({      id: 100000002,      name: "handling",      nametr: "yürütülen"    });    claimtraceprocesses.push({      id: 100000003,      name: "insurance",      nametr: "sigorta"    });    claimtraceprocesses.push({      id: 100000000,      name: "component only",      nametr: "component only"    });    return {      getclaimtraceprocesstypes: function() {        return {          noninsurance: claimtraceprocesses["0"],          inhouse: claimtraceprocesses["1"],          handling: claimtraceprocesses["2"],          insurance: claimtraceprocesses["3"],          componentonly: claimtraceprocesses["4"]        };      },    }  })();    var claimtraceprocesstypes = reports.getclaimtraceprocesstypes();  console.log(claimtraceprocesstypes.componentonly);

i added getclaimtraceprocesstypes function can accessed "claimtraceprocesstypes.inhouse.id" function used.

but when try use object values function below, have values of non-insurance index on componentonly property.

array array2

what doing wrong array ?

your reports object contains property function, if want have objects have execute function:

var reports = (function() {      var claimtraceprocesses = [];    claimtraceprocesses.push({      id: 9,      name: "non-insurance",      nametr: "sigorta dışı"    });    claimtraceprocesses.push({      id: 100000001,      name: "in-house",      nametr: "kurum İçi"    });    claimtraceprocesses.push({      id: 100000002,      name: "handling",      nametr: "yürütülen"    });    claimtraceprocesses.push({      id: 100000003,      name: "insurance",      nametr: "sigorta"    });    claimtraceprocesses.push({      id: 100000000,      name: "component only",      nametr: "component only"    });    return {      getclaimtraceprocesstypes: function() {        return {          noninsurance: claimtraceprocesses["0"],          inhouse: claimtraceprocesses["1"],          handling: claimtraceprocesses["2"],          insurance: claimtraceprocesses["3"],          componentonly: claimtraceprocesses["4"]        };      },    }  })();    console.log(reports.getclaimtraceprocesstypes());

btw suggestion use numbers , not strings accessing properties, if works in way, it's convention, , cannot understand why returning function instead of object directly. think rearrange bit better logic.

i hope helps


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -