Menu

gitpiper

castArray javascript Code Snippet in 2024

typearraybeginner

Last Updated: 14 December 2024

Casts the provided value as an array if it's not one.

  • Use Array.prototype.isArray() to determine if val is an array and return it as-is or encapsulated in an array accordingly.
const castArray = val => (Array.isArray(val) ? val : [val]);
castArray('foo'); // ['foo'] castArray([1]); // [1]

javascript snippet similar to castArray For You in December 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! ✌️