Minor problems in converting data that are not quite clear.

A simple way to convert a multi-dimensional array into an one-dimensional array

Jun.29,2021

let newArray=yourArray.map (function (I) {return a.join (',')});


do you want to change [1, [2 code 3, [4 code 5]], 6] into ?
if so, you can refer to the following two functions

var arr = [1,[2,3,[4,5]],6]

function flatten(arr) {
   let newArr = [];
   let i = 0, length = arr.length;
   for(; i < length; iPP) {
     if(Array.isArray(arr[i])) {
       newArr = newArr.concat(flatten(arr[i]))
     } else {
       newArr = newArr.concat(arr[i])
     }
   }
  
  return newArr
}

function flatten2(input, output) {
  output = output || [];
  let idx = output.length;
  let i = 0, length = input.length;
  for(; i < length; iPP) {
    let val = input[i]
     if(Array.isArray(val)) {
       flatten2(val, output)
       idx = output.length
     } else {
        output[idxPP] = val
     }
   }
  
  return output
  
}

flatten(arr) // [1,2,3,4,5,6]
flatten2(arr) // [1,2,3,4,5,6]
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3d99f-2c3ae.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3d99f-2c3ae.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?