how to give the type to array of objects in typescript code example
Example 1: typescript array of objects
interface User {
[index: number]: {
firstname: string;
lastname: string;
age: number;
}
}
Example 2: typescript array of objects
// Create an interface that describes your object
interface Car {
name: string;
brand: string;
price: number;
}
// The variable `cars` below has a type of an array of car objects.
let cars: Car[];