I have actually a error around delete this.datastore. Ns tried to fix the problem. I gotten rid of the ‘’ however return not correct value. I desire to see variety of entries: 0 at last output. What is the problem ? thanks for help comments.

function clear()Object.keys(this.datastore).forEach(function(key, index) delete this.datastore;);Full Code:

// updates the finish Dictionary course definitionfunction Dictionary()this.add = add;this.datastore = new Array();this.find = find;this.remove = remove;this.showAll = showAll;this.count = count;this.clear = clear;function add(key, value)this.datastore = value;function find(key)return this.datastore;function remove(key)delete this.datastore;function showAll()var datastore = this.datastore;Object.keys(this.datastore).forEach( function(key, index) console.log(key + " -> " + datastore); );function count()var n = 0;Object.keys(this.datastore).forEach( function(key, index) ++n;);return n;function clear()Object.keys(this.datastore).forEach(function(key, index) delete this.datastore;);// making use of the count() and also clear() functionsvar pbook = new Dictionary();pbook.add("Raymond", "123");pbook.add("David", "345");pbook.add("Cynhia", "456");console.log("Number the entries: " + pbook.count());console.log("David"s extension: " + pbook.find("David") + " ");console.log("-------------------------");pbook.showAll();pbook.clear();console.log("Number that entries: " + pbook.count());

You are watching: Cannot convert undefined or null to object

hello snntaylan,

I think that in the clean function, you have to bind “this” to the originating context.

See more: Does Anyone Know The List Of All 18 Vehicles In Far Cry 4 Vehicles

So, making use of an arrow role or advertising datastore favor in the “showAll” role could deal with your problem.

function clear()Object.keys(this.datastore).forEach( (key, index) => delete this.datastore;);Or

function clear() permit datastore = this.datastore;Object.keys(this.datastore).forEach( function(key, index) delete datastore;);
can you please store to one topic in future, girlfriend don’t need to make a new one if it’s because that the same difficulty


Again, very same answer as the critical time, you room using an array as the data store, this can not work, it’s the dorn data structure. Arrays look prefer this:

<"a", "b", "c">You can’t collection the tricks to things that space not indices: variety cannot have actually a value “123” at index “Raymond”, that’s nonsensical