Skip to content

Instantly share code, notes, and snippets.

@kevinchisholm
Last active December 18, 2019 12:25
Show Gist options
  • Save kevinchisholm/8df083ec1f35d68cad0d523525a0d3e4 to your computer and use it in GitHub Desktop.
Save kevinchisholm/8df083ec1f35d68cad0d523525a0d3e4 to your computer and use it in GitHub Desktop.
Check if array has length
// 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