Attempting to insert data into a JavaScript Array within my constructor has resulted in this error message:
TypeError: this.listeetudiant is undefined
This is my constructor:
function Cours(){
*/the array causing trouble: */
this.listeetudiant=[];
*/ the method intended to utilize the array's content and add data to it */
this.affForm=printForm;
}
Subsequently, I attempted to add data to listeetudiant using the method, only to encounter issues:
function printForm(){
this.listeetudiant.push = (1);
}
Furthermore, I attempted
this.listeetudiant.push(etudiant[id].id);
where etudiant[id].id is a valid variable...
Unfortunately, the issue persists and the error message "TypeError: this.listeetudiant is undefined" is displayed.
Please lend me a hand!
It functions properly when adding one data to a single variable. However, encountering challenges with arrays! I require the ability to insert multiple data into my array listeetudiant at various intervals, which seems unachievable.
For instance, if I write:
function printForm(){
this.listeetudiant=(1);
alert(this.listeetudiant);
}
it performs as expected, with listeetudiant's value becoming 1 within my object. The dilemma lies in the necessity of adding multiple values to listeetudiant as an array — a capability I'm struggling to achieve!