// ForEach Example
var School;
School = new Array("Principal", "Mr. Garrison", "Chef");
School.forEach(listItem)
function listItem(item){
NSB.Print(item);
}
Line 5: | Line 5: | ||
ForEach calls ''function'' on each element of ''array''. | ForEach calls ''function'' on each element of ''array''. | ||
The BASIC implementation of this function is consistent with [ | The BASIC implementation of this function is consistent with [https://documentation.help/MS-Office-VBScript/vsstmForEach.htm VBScript]: ''element'' is a simple variable which gets the value of each element in the ''array'' sucessively. | ||
If you're using JavaScript, the | If you're using JavaScript, the [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach JavaScript specification] is fully supported. | ||
== Example == | == Example == |
ForEach(array, function)
ForEach calls function on each element of array.
The BASIC implementation of this function is consistent with VBScript: element is a simple variable which gets the value of each element in the array sucessively.
If you're using JavaScript, the JavaScript specification is fully supported.
// ForEach Example
var School;
School = new Array("Principal", "Mr. Garrison", "Chef");
School.forEach(listItem)
function listItem(item){
NSB.Print(item);
}
Rem ForEach Example
Dim School
School = Array("Principal", "Mr. Garrison", "Chef")
ForEach(School, listItem)
Function listItem(item)
Print item
Next
Principal Mr. Garrison Chef