Returns the first element of an array or the value itself if it's not an array.
firstOrSelf('Hello'); // 'Hello'firstOrSelf(['Hello', 'World']); // 'Hello'firstOrSelf([]); // undefinedfirstOrSelf(null); // undefinedfirstOrSelf(undefined); // undefinedfirstOrSelf(0); // 0firstOrSelf(''); // ''firstOrSelf(false); // false Copy
firstOrSelf('Hello'); // 'Hello'firstOrSelf(['Hello', 'World']); // 'Hello'firstOrSelf([]); // undefinedfirstOrSelf(null); // undefinedfirstOrSelf(undefined); // undefinedfirstOrSelf(0); // 0firstOrSelf(''); // ''firstOrSelf(false); // false
Returns the first element of an array or the value itself if it's not an array.