When the callback function is executed for an element, the elements value and index will be passed to it and this information is logged. Here, we use the required parameter of the callback function which is the value and an optional parameter which is the index. Description: A generic iterator function, which can be used to seamlessly iterate over both objects and arrays. The forEach () method is not executed for empty elements. The code below logs the elements in the array colors along with each element's index. The forEach () method calls a function for each element in an array. function addTwoNumbers(num1, num2) Example 2: Log the elements of an array along with their index This is because, in Apps Script (which is a version of JavaScript), a function is basically a variable with a value of type function.Ĭonsider the function addTwoNumbers() below. Notice that there is no name for the function in the above example.
0 Comments
Leave a Reply. |