Menu

gitpiper

head javascript Code Snippet in 2024

arraybeginner

Last Updated: 11 April 2024

Returns the head of an array.

  • Check if arr is truthy and has a length property.
  • Use arr[0] if possible to return the first element, otherwise return undefined.
const head = arr => (arr && arr.length ? arr[0] : undefined);
head([1, 2, 3]); // 1 head([]); // undefined head(null); // undefined head(undefined); // undefined

javascript snippet similar to head For You in April 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️