1

experience(years)d.o.b (dd/mm/yyyy) -- how can I remove (),.,/, spaces from the string using single replace function in node. I would like to get like

experienceyearsdobddmmyyyy

//pgm converts xl to json

const exceltojson = require('xlsx-to-json');
const fs = require('fs');
exceltojson({
    input: "xl.xlsx",
    output: 'xl.txt',// Don't need output
    sheet: 'student_Details'
  },
  function(err, result) {
    if (err) {
      console.error(err);
      return;
    }
    else{
      console.log(result+'   result')
      console.log(result)
    }
    const newResult = result.map(obj => {
      const newObj = Object.keys(obj).reduce((acc, key) => {
        const newKey = key.replace(/ /g, '').toLowerCase();
        acc[newKey] = obj[key];
        console.log(newKey+'   newKey ')
        return acc;
      }, {});
      return newObj;
    });
    fs.writeFileSync('xl.json', JSON.stringify(newResult));
  }
)
3
  • please add the current working code with actual output and desired output Commented May 5, 2020 at 18:23
  • my code is a conversion code from excel to json Commented May 5, 2020 at 18:24
  • the above code converts excel to json and make all the headers in lowercase and remove spaces, but I would also like to remove special charcters from my keys Commented May 5, 2020 at 18:28

2 Answers 2

3
> re = /[\(\)\/\.\ ]+/g
/[\(\)\/\.\ ]+/g
> s="(10/04/2020)"
'(10/04/2020)'
> s.replace(re, "")
'10042020'
Sign up to request clarification or add additional context in comments.

Comments

2

you can use regex to replace all those chracters.

let str = "experience(years)d.o.b (dd/mm/yyyy)";

function stripedStr(s){
  return s.replace(/[\(,\),\.,\/,\-,\_, ,]/g, "");
}

console.log(stripedStr(str));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.