JS Built-ins
TypeScriptbeginner

Type Guard β€” isArray

πŸ“– Usage Example
function isArray(x: unknown): x is unknown[] {
  return Array.isArray(x)
}
isArray([1, 2])   // β†’ true
isArray('abc')    // β†’ false

Array.isArray() is the reliable way to check for arrays, handling cross-frame edge cases.

Type Guards: isArray

Challenge: Implement isArray(x: unknown): x is unknown[].

isArray([1, 2, 3])  // β†’ true
isArray({})         // β†’ false
πŸ’‘ Hints (1)
  • β€’ Array.isArray() is the standard way to check for arrays.