Javascript method parameters | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Javascript method parameters

Hi @all, I need help. I`m new to Javascript and want to train a littlebit. In my script I loop an array. This array has two identifiers and values. Let's say ID and Text. Now, I want to call a method and pass the line of the array. But without to pass each Identifier. I hope there is something like this: For(wa in array) { MyMethod(wa) }; MyMethod(wa) { Allert(wa.id); Allert(wa.text); }; Thanks Helge

26th Sep 2019, 8:36 PM
Helge Hauffe
Helge Hauffe - avatar
3 Answers
+ 1
You can try it like this: array.forEach(MyMethod); MyMethod(value, index, array){ Allert(value.id); Allert(value.text); };
26th Sep 2019, 9:18 PM
Irma Masleša
Irma Masleša - avatar
0
it seems that with forEach I can only call functions and not methods of my class?!
27th Sep 2019, 5:58 AM
Helge Hauffe
Helge Hauffe - avatar
0
Did you try calling function with this.functionName?
27th Sep 2019, 6:36 AM
Irma Masleša
Irma Masleša - avatar