I have tried moving the array before, after the constructor. I am pretty sure I have the syntax wrong at this point, I have tried researching for quite some time without luck. Any help would be appreciated.
class dataService {
constructor() {
}
//I need to be able to initialize this array of objects and create an empty constructor which does nothing
var data = [ // Error: Construcotr, method, accessor, or property was expected
name1 = { name: "Mitchell", gender: "male", address: "201 Burns Street East", age: 20, phoneNumber: "905-550-7379" },
name2 = { name: "Bob", gender: "male", address: "555 Hello Street", age: 25, phoneNumber: "123-456-7891" },
name3 = { name: "Gillian", gender: "female", address: "457 Baker Street", age: 23, phoneNumber: "555-111-999" }
];
getData(numRecords) {
numRecords = numRecords || undefined;
if (numRecords == undefined) {
return data;
}
};
}
this.data = [ /* your array data */ ]in the constructor?[{ name: "Mitchell", gender: "male", address: "201 Burns Street East", age: 20, phoneNumber: "905-550-7379" }, { ... }, { ... }](without the "name1", "name2", "name3" labels) or you use an object{ name1: { name: "Mitchell", gender: "male", address: "201 Burns Street East", age: 20, phoneNumber: "905-550-7379" }, name2: { ... }, name3: { ... } }.