I am trying to convert elements of an array to independent arrays and then adding these arrays to a new array. this is what i have tried. But cannot get it to work.
splice method is not working properly with forEach,forEach just runs for half array and then exits.
what i expect is something like this [['Apple'],['Banana'],['Mango'],['Pomegranate']]
const fruits = ['Apple', 'Banana', 'Mango', 'Pomegranate']
function removeArrayItem(item,index){
return fruits.splice(0,1)
}
const fruitsList = []
fruitsList.unshift(fruits.forEach(removeArrayItem))
console.log(fruitsList)
.map()makes a lot more sense than.forEach().