When trying to construct a class by passing in an array of strings, the new object string array is empty.
I've tried several different approaches to initialize the new objects string array in the constructor, including, but not limited to the following:
this.newArray = oldarray.slice();
this.newArray = Array.from(oldarray);
this.newArray = oldarray.map( s => { return s; });
iterating through the old array and pushing the elements one at a time in to the new array.
What is interesting here is that the when creating the for loop, I noticed that the string array acts like it has a property called "array". So the for loop wouldn't process because oldarray.length = 0, but oldarray.array.length = 5
I'm able to see this in the debugger. If I attempt to change the code to reference oldarray.array, it underlines and complains about the .array portion and fails to compile under ng serve.
I know this is probably going to end up being something easy / stupid, and its just a matter of me staring at the same code for several hours.
export class Widget {
public role: string;
public array: WidgetTuple[];
constructor(role: string, tuplearray?: WidgetTuple[]) {
this.role = role;
this.array = [];
if (tuplearray != undefined) {
for (var lcv = 0; lcv < tuplearray.length; lcv++) {
var tupl = new WidgetTuple(tuplearray[lcv].widgetGrouper);
this.array.push(tupl);
}
}
}
}
export class WidgetTuple {
public widgetGrouper: string[];
constructor(strvalues?: string[]) {
this.widgetGrouper = [];
if (strvalues != undefined) {
this.widgetGrouper = strvalues.slice();
//this.widgetGrouper = strvalues.map()
//for (var lcv = 0; lcv < strvalues.length; lcv++) {
// var entry = strvalues[lcv].toString();
// this.widgetGrouper.push(entry);
//}
}
}
}
I expect the string elements from the original widgetGrouper string array to be included in the new WidgetTuple object that is added to the Widget array.
All attempts so far, yield empty string array results in the newly created object.
Thank you in advance for your assistance.
This didn't format well in my comment, so here it is, hitting the debug breakpoint in VS and looking at strvalues:
- strvalues Array(0) [] Object
+ array Array(4) ["widgetone", "widgettwo", "someitem", …] Object
length 0 number
+ __proto__ Array(0) [, …] Object
the string array acts like it has a property called "array"- Are you just referring to the browser console? They typically just say "Array" or "Object" just to make it clear what it is.WidgetTuple[]in to your constructor.