An array is an ordered collection whose elements are accessed by zero-based position. JavaScript arrays resize dynamically, accept mixed value types, and use square-bracket syntax. Create an empty array, then add values with push; read or replace an element with its index. section 3.4
A practical JavaScript array
The names array starts with three strings, while prices grows as values are appended. The example deliberately mixes numbers and strings, then converts values before calculating a numeric total. It prints Hat as the first item and a total of 250.25.
TypeScript preserves JavaScript’s flexible length but can restrict element types. Write number[] or string[] annotations, and use (number | string)[] when a union is intentional. Typed arrays let callbacks such as forEach receive values with the declared type, enabling operations such as toFixed only on numbers. section 9.2
Common array operations include:
- Arrays of objects inherit their element type from object shape; mixing shapes can leave only common properties safely available. section 10.2







































