xxxxxxxxxx
let indexedArray: {[key: string]: number}
let indexedArray: {[key: string]: number} = {
foo: 123,
bar: 456
}
indexedArray['foo'] = 12;
indexedArray.foo= 45;
xxxxxxxxxx
const myObj = { a: 1, b: 'some_string' } as const;
type values = typeof myObj[keyof typeof myObj];
xxxxxxxxxx
interface MyObjectType {
property1: number;
property2: string;
// Add more properties as needed
}
// Usage example
const myObject: MyObjectType = {
property1: 10,
property2: "Hello world",
// Assign values to other properties
};
xxxxxxxxxx
class Planet
{
name: string;
galaxy: string;
numberOfMoons: number;
weight: number;
}
let earth = new Planet("Earth", "Milky Way", 1, 10000);
let jupiter = new Planet("Jupiter", "Milky Way", 21, 2000000);
TypeScriptCopy
xxxxxxxxxx
numobj:any={}
ngOnInit(){
numobj["positive"]={
"ODD":[1,3,5,7],
"event":[2,4,6,8]
}
console.log(numobj)
}