Quick actions

cmd+k|ctrl+k

Navigation

Languages

replace html entity

Snippet info

Language

JavaScript

Visibility

public

Author

jsonkody

Created

2026-06-17T09:47:11.475033Z

Updated

2026-06-17T12:37:24.726578Z

const o = {
    title: "Toto je:\\ntitle — test .. —____— –__– ’’tst’’",
    note: "Toto je:\\nnote — test .. —____— –__– ’’tst’’"
}


function fix_string(str) {
       let new_str = str

    const replace_arr = [
      ['—', '—'],
      ['–', '–'],
      ['’', '’'],
      ['\\n', '\n'],
   ]
   replace_arr.forEach(replace => (new_str = new_str.replaceAll(replace[0], replace[1])))

   return new_str
}

function fix_obj_strings(o) {
    o.title = fix_string(o.title)
    o.note = fix_string(o.note)
}

// console.dir(o)
// console.log('\n')

fix_obj_strings(o)

// console.dir(o)
// console.log('\n')

console.log(o.title)
// console.log('\n')
console.log(o.note)
INFO