Skip to content

Instantly share code, notes, and snippets.

@victorpolko
Last active September 13, 2025 13:06
Show Gist options
  • Save victorpolko/ffd1857f031f3aa47cb3ad934931bbcd to your computer and use it in GitHub Desktop.
Save victorpolko/ffd1857f031f3aa47cb3ad934931bbcd to your computer and use it in GitHub Desktop.
JavaScript: get array length without `.length`
function arrLength(arr) {
if (!arr || !arr[0]) return 0;
const [_head, ...tail] = arr;
return 1 + arrLength(tail);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment