Last active
December 18, 2019 12:25
-
-
Save kevinchisholm/8df083ec1f35d68cad0d523525a0d3e4 to your computer and use it in GitHub Desktop.
Check if array has length
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example # 1: check if the length property of the passed-in array is 0 | |
function processRecords (records) { | |
if (records.length === 0) { | |
console.log(`No records to process`); | |
return; | |
} | |
records.forEach(record => { | |
console.log(`The record is: ${record}`); | |
}); | |
} | |
processRecords(['foo', 'bar', 'baz']); | |
// The record is: foo | |
// The record is: bar | |
// The record is: baz | |
processRecords([]); | |
// No records to process | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment