const addEscapeCodes = [' ', '!', '$', '*', "\\", '|', '"', "'", '?', '<', '>']; const str = "/tes t4*4!"; function replaceCode(str) { let result = '' for (let i = 0; i < str.length; i++) { result += addEscapeCodes.includes(str[i]) ? `\\${str[i]}` : str[i] } return result } replaceCode(str) const list = [ { "TargetNameService": "HDFS16000372", "TargetPath": "/test44", "GlobalPath": "/test44" } ] // list.map(item=>({ // ...item, // GlobalPath: // }))