Maciaz
Maciaz

Reputation: 1224

Code snippet explaination, function parameters

I'm a beginner Java dev and need to use JS script in my app, so please take it easy on me. I found a code in Javascript and I'm trying to understand it.

The code snippet:

window.NETWORK_STAT_MAP = new Map(networkStat[symbol.toLowerCase()]);

NETWORK_STAT_MAP.forEach(function(url, host, map) {
$.getJSON(url + '/stats', function(data, textStatus, jqXHR)

Upvotes: 1

Views: 46

Answers (1)

ben
ben

Reputation: 3568

I guess you should have a look at MDN :
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach

The forEach method executes the provided callback once for each key of the map which actually exist. It is not invoked for keys which have been deleted. However, it is executed for values which are present but have the value undefined.

callback is invoked with three arguments:

  • the element value

  • the element key

  • the Map object being traversed

for JSON, if you are searching for forEach yes, it is native. For instance

const JSON = {
   data: [1, 2, 3]
}
JSON.data.forEach(/*...*/)

Upvotes: 2

Related Questions