What is the meaning of this code block?

What is the meaning of this code block?
0

#1

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]);
    });
}

#2

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


#3

I know object.keys functionality. Sorry, exactly I could not understand you.


#4

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