Menu

gitpiper

castArray javascript Code Snippet in 2022

typearraybeginner

Last Updated: 25 September 2022

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 September 2022

Subscribe to our Newsletter

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

© 2022 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! ✌️