I would like to get the items in var a
, a two-dimensional Array, and iterate in a nested loop, concatenating everything, to put them in brackets, separated by a slash, as shown by the desired result logo below, which will be stored in var b
. The problem is that the bars and brackets do not look the way you expect.
/*
Resultado Desejado:
Array [ "[advice / advices]", "[are / is]" ]
Resultado Obtido (Indesejado):
Array [ "[advice /advices /", "[are]is]" ]
*/
var a = [
['advice', 'advices'],
['are', 'is']
];
var b = [];
for (var i = 0; i < a.length; i++) {
var c = ['['];
for (var j = 0; j < a[i].length; j++) {
if (i < a[i].length - 1) {
c += a[i][j].split(',').toString().trim() + ' /';
}
if (i == a[i].length - 1) {
c += a[i][j].split(',').toString().trim() + ']';
}
}
b.push(c);
}
console.log(b); // Array [ "[advice /advices /", "[are]is]" ]