Drew13 Drew13 - 29 days ago 26
TypeScript Question

Access an array from another Typescript file

I have an array

DPS
in one of my Typescript files that is not defined in a class in that file, it's just sitting by itself.

const DPS: DataTable[] = [
{ tDataPoint: "d1", tICCP: "i1", tStartDate: "s1", tEndDate: "e1" },
{ tDataPoint: "d2", tICCP: "i2", tStartDate: "s2", tEndDate: "e2" },
{ tDataPoint: "d3", tICCP: "i3", tStartDate: "s3", tEndDate: "e3" },
{ tDataPoint: "d4", tICCP: "i4", tStartDate: "s4", tEndDate: "e4" }
];


In another Typescript file in a different component directory I want to access this array to manipulate it.

Answer

I was able to add export before const when declaring the variable array. Then import the variable into the other Typescript file import { DPS } from '../mainpage/mainpage.component';. Then all I wanted to do with that array was delete an entry so to manipulate that array I just used dot notation. DPS.splice(0,1);.