I am struggling with a function that is supposed to accept an array as parameters and then log all the elements of the array into a single new array. However, the issue I am facing is that each array element is being printed separately instead of combined into one array. Here is my code:
const result = []
function combineArrayElements(arr){
//your code here
for (let i = 0; i < arr.length; i++) {
const element = arr[i];
console.log(new Array(element))
}
}
combineArrayElements("AAAA") \\ is printing ['A'], ['A'], ['A'], ['A']
\\ Instead of ['A', 'A', 'A', 'A']