Friday, 15 May 2015

javascript - value++ in for loop itself -


I have a lot of simple questions about loop in javascript. After running a method I am trying to increase the value (in j in my code), which declares the callback method and in that function I increase the value. But my code breaks, and I'm not sure it's a valid JavaScript.

< / P>

For code> (j = 0; j & lt; = 5;) {var keyContent = window.localStorage [window.localStorage.key (j)]; Console.log (keyContent); Var dataform = JSON.parse (keyContent); Upload data and image (data form, function) {console.log (data); if (data) {console.log ("data is good"); j ++;} else {console.log ("data bad") ; Break;}}); }

Edit: This did the job by doing:

  var formDataArray = []; {Var keyContent = window.localStorage [window.localStorage.key (j)] for (J = 0; J & lt; = 5; J ++); Console.log (keyContent); Var dataform = JSON.parse (keyContent); FormDataArray [j] = JSON.parse (keyContent); UploadDataAnimage (formDataArray [j], function (data) {console.log (data); if (data) {console.log ("data good");} else {console.log ("data bad"); return;} }); }  

If you need to increase your loop, what do you want While loop :

  var j = 0; Whereas (j & lt; = 5) {var keyContent = window.localStorage [window.localStorage.key (j)]; Console.log (keyContent); Var dataform = JSON.parse (keyContent); Upload data and image (data form, function) {console.log (data); if (data) {console.log ("data is good"); j ++;} else {console.log ("data bad") ; Break;}}); }  

No comments:

Post a Comment