How to replace the null value of js json array with'-'

[
{name:a,id:""},
{name:c,id:"d"},
{name:b,id:""},
{name:y,id:"d"},
{name:s,id:6},
{name:p,id:3},
]

how does the data from the background replace all the empty ones with"-"

Oct.30,2021

just write a regular replace replacement, right? Your data is not embedded deeply,


let arr = JSON.parse (data)
arr = arr.map (e = > {.e, id: e.id =''?'-': e.id})


can be replaced when displayed on the page, and there is no need to change the array. If you have to change the array, you can do this:

arr.forEach(v=>{  
    if(v.id == "") {
        v.id = "-";
    }  
});

   

Menu