У меня есть 2 массивыДля цикла с 2 синтаксического анализа массивов
var a = [
"4",
"@",
"/\\",
"/-\\",
"^",
"∂",
"λ",
"α",
"(!",
"Z",
"α"
];
var r = [
"1²",
"2",
"?",
"P\\",
"[\"/_",
"l\"/_",
"|-",
"|2",
"|?",
"®",
"12",
"/2",
"I2",
"|^",
"|~",
"(r)",
"|`",
"l2",
"Я",
"ʁ",
"я"
];
мне нужно Парс в 1 для постановки оба массива
Вот что у меня есть:
for (var index_a=0, index_r=0; index_a < a.length, index_r < r.length ; ++index_a, ++index_r) {
new_a = a[index_a];
console.log(new_a);
new_r = r[index_r];
console.log(new_r);
};
Выход:
the element from A array: 4
the element from R array: 1²
the element from A array: @
the element from R array: 2
the element from A array: /\
the element from R array: ?
the element from A array: /-\
the element from R array: P\
the element from A array:^
the element from R array: ["/_
the element from A array: ∂
the element from R array: l"/_
the element from A array: λ
the element from R array: |-
the element from A array: α
the element from R array: |2
the element from A array: (!
the element from R array: |?
the element from A array: Z
the element from R array: ®
the element from A array: α
the element from R array: 12
the element from A array: undefined
the element from R array: /2
the element from A array: undefined
the element from R array: I2
the element from A array: undefined
the element from R array: |^
the element from A array: undefined
the element from R array: |~
the element from A array: undefined
the element from R array: (r)
the element from A array: undefined
the element from R array: |`
the element from A array: undefined
the element from R array: l2
the element from A array: undefined
the element from R array: Я
the element from A array: undefined
the element from R array: ʁ
the element from A array: undefined
the element from R array: я
Проблема в том, что один массив длиннее затем другой, и после завершения разбора кратчайший он продолжает оставаться самым длинным, но значение для кратчайшего не определено. Мне нужно, чтобы когда заканчивался самый короткий массив, последнее значение должно быть сохранено. Как я могу это сделать. Спасибо.
Вам нужен только последний элемент? – baao
непонятно, что вы хотите сделать, когда первый массив заканчивается - перестаньте цикл по второму, или продолжайте только на нем? –
Почему бы не объединить массивы и не перебрать все элементы? – Alex