Count how many times a conditional is true inside for loop with javascript

<p>I have a for loop that runs over a range of cell values in a Google Apps script I'm trying to write, and each time it loops, it checks to see if a certain condition is true. If it's true, for the time being, it's logging the results to Logger.log().</p><p>I need the total number of results that show up in Logger.log() (in this case, it would be 10) and the best way I was able to think of doing that would be to count up by 1 each time that conditional is true in the for loop. It should be very simple to get a numerical value of how many results.</p><p>Here's the code I'm using:</p><pre><br /><code>var currentsheet = SpreadsheetApp.getActiveSheet();<br />var values = currentsheet.getRange("A28:E").getValues();<br /><br />for (i=0; i<values.length; i++) {<br />if (values[i][3] === "Section 179 Depreciation") {<br /> var date = values[i][0];<br /> var amount = values[i][1];<br /> var desc = values[i][2];<br /> var expType = values[i][3];<br /> var notes = values[i][4];<br /><br /> }<br />}<br /></code><br /></pre><p>What am I missing?</p><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34525729/count-how-many-times-a-conditional-is-true-inside-for-loop-with-javascript">http://ift.tt/1NQ8jqT</a></h2>

Nhận xét

Bài đăng phổ biến từ blog này

Align div to bottom of the page in bootstrap

Align elements inside an tag vertically

Javascript is unable to stop page loading