Database string array, after removing redundant symbols, it will be converted to string output

Requirement : The string of provinces and cities extracted from the database region: ["Shaanxi Province", "Xi'an", "Yanta District"] to: Yanta District, Xi'an, Shaanxi Province  

1. First convert the string to an object: var obj = JSON.parse(region);

2. Then turn the object into a string and output: obj.join('').

Method continuous call: JSON.parse(defaultAddress.region).join('')

Reference Code:

    if (region!= '' && region!= null && region!= undefined) {

       console.log(region) //["陕西省","西安市","雁塔区"] 
       var region = JSON.parse(region).join('')
       console.log(region)  //陕西省西安市雁塔区
       that.setData(           
           region: region
       })
   }

Print output situation:

Guess you like

Origin blog.csdn.net/qq_29644709/article/details/88800610