Created
March 31, 2018 16:04
-
-
Save mkhuda/1dafcc67a05a0c2730db0c7bfc8c9acd to your computer and use it in GitHub Desktop.
Looping array by indexing some number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ar = ["5", "3", "jhj", "opp", "tyt", "hkl", "aji", "6", "3", "kak", "lop", "gyt", "uyt", "ert", "wqa", "2", "3", "hhh", "bbb", "2", "5", "jonru", "bando"]; | |
var i = 0; | |
var x = 0; | |
var reschild = []; | |
var resparent = []; | |
var m = 0; | |
while (i < ar.length) { | |
count_row = parseInt(ar[i]); | |
length_text = parseInt(ar[i+1]); | |
if(count_row > 0){ | |
first_x = i + 2; | |
reschild = []; | |
n = 0; | |
for (x = first_x; x < count_row + i + 2; x++) { | |
reschild[n] = ar[x]; | |
n++; | |
document.getElementById('jajaltxt').value = document.getElementById('jajaltxt').value + ar[x] + ","; | |
} | |
i = x; | |
resparent[m] = reschild; | |
document.getElementById('jajaltxt').value = document.getElementById('jajaltxt').value + ";"; | |
} else { | |
alert("invalid array"); | |
break; | |
} | |
m++; | |
alert(i); | |
} | |
alert(JSON.stringify(resparent)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment