Reputation: 1224
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)
NETWORK_STAT_MAP
is a JS map. networkStat
is an iterable. function(url, host, map)
call on each of map's items. Are function parameters variables in the map's items? Or should they be declared somewhere else in the .js file? Upvotes: 1
Views: 46
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