javascript - Why the value inside the loop and using the [i] is undefined? -


When using the Mozilla JetPack, when I do the following code .. I think the link is undefined! Why ? Or how to fix it?

  var link = doc.querySelectorAll ('# curriculum_manu> gt; ul & gt; li & gt; a'); Var linkz = links [1] .href.split ("?"); Var i = 0; (I = 0; i & lt; = 4; i ++) for {var linking = links [i]; } Jetpack.notifications.show ("" + linking);  

Because it exits scope when the loop is over.

So you should be

  var linking; For (i = 0; i & lt; = 4; i ++) {linking = links [i]; }  

But apart from that, what are you trying to do here? Do you overwrite the link four times Do you want to display all the links? If so, you can add them to:

  var linking = ""; {Linking = linking + links [i] + "" for I (i = 0; i  

Edit: Commenters are right; I forgot that there is no block scrap in javascript. Does it fix your code? I can not imagine that it did it. The only other thing I can think of is that the link [4] is undefined, and then you are specifying undefined to link .

Anyway, I can not remove it because it has been accepted, but if any other useful answer comes along, feel free to reject it without it.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -