Friday 19 May 2017

Replace value within string value

I am trying to look through the JSON response and replace every time "Sw" appears in a string(value). For instance, take this JSON object:

[{"accountName":"MTVN\\lalalala",
  "baseOfficeLocation":"657 Hudson Street Floor 11",
  "department":"Mp - Engineering - Engineering",
  "jobTitle":"Sw Test Engineer",
  "preferredName":"Beddingfield,Natasha",
  "workEmail":"Natasha.Beddingfield@viacom.com"}]

I'd like to replace everytime I get a response that includes those butchered words like "Mp" and "Sw"and replace them with it's whole word. So "Sw" would become "Software".

Here is some code i have so far, but I am not that experienced at all in node.js, so would like to know how to accomplish this (:

var baseOfficeLocation = jsonData.baseOfficeLocation;
            console.log("Base Office Location: " + baseOfficeLocation);
            var department = jsonData.department;
            console.log("Department: " + department);

            var workEmail = jsonData.workEmail;
            console.log("Work Email: " + workEmail);

            if (jsonData.jobTitle !== null) {
                replaceString(jsonData.jobTitle, 'Sw', 'Software');
            }
            console.log("Job Title: " + jobTitle);



via VeeArr

No comments:

Post a Comment