how to remove newline from data received in node js with puppeteer

I need help with the below code. How do I remove all the newline n in the rawTxt output? The current output for rawTxt is rawTxt: ‘nnnnnnnnKangol Men, Women Washed Bucket Hatnnnnnnn’

I tried .replace(/n/g) and .replace([sS]) but no luck. Been searching around all day today but no luck 🙁

const puppeteer = require('puppeteer');

async function scrapeProduct(url) {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto(url);

    const [el] = await page.$x('//*[@id="landingImage"]');
    const src = await el.getProperty('src');
    const srcTxt = await src.jsonValue();

    const [el2] = await page.$x('//*[@id="productTitle"]'.replace(/n/g, ''));
    const txt = await el2.getProperty('textContent');
    const rawTxt = await txt.jsonValue();

    console.log({srcTxt, rawTxt});

    browser.close();
}

scrapeProduct("https://www.amazon.com/Kangol-Mens-Washed-Cotton-Bucket/dp/B0758LZQW6/ref=sr_1_17?dchild=1&keywords=bucket+hat&qid=1609973810&sr=8-17");

// { srcTxt: 'https://images-na.ssl-images-amazon.com/images/I/41TF7rSBy8L._AC_UX342_.jpg', rawTxt: 'nnnnnnnnKangol Men, Women Washed Bucket Hatnnnnnnn' }

Answer

You can try the folowing code:

const input = 'nnnnnnnnKangol Men, Women Washed Bucket Hatnnnnnnn';

console.log('initial input=', input);
console.log('new input =', input.replaceAll('n',''));