Hi, someone help me please. I know what is this Object.keys and forEach. But I could not understand full of code block. Thanks for helping
Object.keys(this.datastore).forEach(function(key, index) {
Full code in below:
function showAll() {
Object.keys(this.datastore).forEach(function(key, index) {
console.log(key + "->" + this.datastore[key]);
});
}
It’s just console logging the name and value of every key in the datastore object, so like
datastore = {
foo: 1,
bar: 2,
baz: 3
}
Will give the result
"foo" -> 1
"bar" -> 2
"baz" -> 3
In the console
I know object.keys functionality. Sorry, exactly I could not understand you.
Object.keys collects all the keys of an object called datastore. forEach loops through this collection of keys. For each key, print "key" -> corresponding value