Linked Questions

Popular Questions

How to retrieve data outside of function in Javascript?

Asked by At

I am using xml2js node module https://www.npmjs.com/package/xml2js

I am parsing XML data into JSON

But how do I get the value outside this function?

var parseString = require('xml2js').parseString;

// My XML Data
var xml = "<root>my xml data</root>"

// Function to parse xml to json
parseString(xml, function (err, result) {
    console.dir(result);
});

I am looking to get the parsed value result out of the function so that I can use it at different components?

const jsonOutput = result;

Related Questions