The problem of string array replacement step by step

The goal of

is to replace the null string in each element with the next element, resulting in a replacement string.

related codes

/ / the list array is as follows

var list = [
  "data : {null}", 
  "item : ( payload.data.list map(value0, index0) -> {null})",
  "gradeList : ( value0.gradeList map(value1, index1) -> {null})", 
  "otherList : ( value1.otherList map(value2, index2) -> {null})", 
  "anotherList : ( value2.anotherList map(value3, index3) -> {null})"
]

the desired result is a string

 "data : {
    item : ( payload.data.list map(value0, index0) -> {
        gradeList : ( value0.gradeList map(value1, index1) -> {
          otherList : ( value1.otherList map(value2, index2) -> {
            anotherList : ( value2.anotherList map(value3, index3) -> {null})
          })
        })
    })
  }"
Jun.24,2022


for (let i = list.length - 2; i >= 0; i--) {
  list[i] = list[i].replace(/{\s*null\s*}/, `{\n ${"\t".repeat(i)}${list[i + 1]} }`);
}

for (var i = list.length-1,str=''; i >= 0; i--) {
  (obj = list[i].replace(/null/,str),str = obj);
}
console.log(str);
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-1b36600-2b557.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-1b36600-2b557.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?