Get all the elements of a two-dimensional array and concatenate them
Topic request
Thought analysis
Code implementation
// Get all the elements of the two-dimensional array and assemble them into a "gold digger, programmer's dream factory"
var arr = [
["Dig"."Gold"."Network"],
["Cheng"."Order"."Member"],
["Dream"."Work"."Plant"]].// Add missing contents to array, i.e. "," and "of"
arr[0].push(', ');
arr[1].push('the');
// Define the STR to hold the result
var str = ' ';
var newArr = [];
// Loop over each item in the two-dimensional array
for (var i = 0; i < 3; i++) {
for (var j = 0; j < 4; j++) {
newArr.push(arr[i][j]);
}
}
newArr.length -= 1;
str = newArr.join(' ');
console.log(str);
Copy the code