The original data

  const obj = {
      "textA": 32."textB":[
        {
          "1":"22"},]."textC": [1, 2, 3],"textD": {"textD-1": ["The number"]."textD-2":[
              {"name":"Agricultural and sideline Food Processing industry"."data": ["2"] {},"name":"Water production and supply."."data": ["1"]}],"textD-3": {"demo": [11]."test": 22}},"textE": "textE"."textF": true."textH": [[1], [{2, {1: [] {2: [1]}}}], [3]]}Copy the code

The processing method carries out deep recursion

const fomatterData = data => {
  const result = {};
  for (let key in data) {
    const type = judgeType(data[key]);
    if (type! = ="Object" && type! = ="Array") {
      result[key] = type;
    } else if(type= = ="Array"){
        const res = formatterDeepArray(data[key])
        result[key] = res
    }else{
        result[key] = fomatterData(data[key])
    }
  }
  return result
};
Copy the code

Accurate judgment type

const judgeType = data => {
  const res = Object.prototype.toString.call(data);
  return /^\[object (.*)\]$/.exec(res)[1];
};
Copy the code

Handles recursion when type is data

const formatterDeepArray = (data)=>{
    let result
    if(data.length === 0) {
        result = "any"
    } else{
        result = []
        data.map((i)=>{
            const type = judgeType(i)
            if (type! = ="Object" && type! = ="Array") {
                result.push(`${type}`)}else if(type= = ="Array"){
                result.push(formatterDeepArray(i))
            }else{
                result.push(fomatterData(i))
            }
        })
    }
    return result
}
Copy the code

The results of

{
  "textA": "Number"."textB": [{"1": "String"}]."textC": [
    "Number"."Number"."Number"]."textD": {
    "textD-1": [
      "String"]."textD-2": [{"name": "String"."data": [
          "String"] {},"name": "String"."data": [
          "String"]}],"textD-3": {
      "demo": [
        "Number"]."test": "Number"}},"textE": "String"."textF": "Boolean"."textH": [["Number"], [{"2": {
          "1": [{"2": [
                "Number"]}]}}], ["Number"]]}Copy the code