Steps to get the solution: 1. Loop over the array keys using for loop 2. If current item is an Array, call flatten method recursively with current item as parameter, also pass result Array to use it in recursive calls. 3. If type of current item is not an Array, we can add the current property to result Array. Please find the code to flatten an arrray in JavaScript below:

 const flatten = (arr,result=[]) => {
	 for(let i=0;i<arr.length;i++) {
	   if(Array.isArray(arr[i])) {
	   else  {
	 return result;

 const arr=[1,2,[5,3,4,[7,8,9,[10,11]]]];
 console.log(flatten(arr)); //   [1,2,5,3,4,7,8,9,10,11];
 //using inbuilt function flat //
 const result=arr.flat(Infinity);
 console.log(result); //   [1,2,5,3,4,7,8,9,10,11];