I have an array of JSON objects and I am trying to extract it as key-value pairs. Here is the code snippet:
var fs = require('fs');
var parameters =
{
'Tenantid': 'a62b57-a249-4778-9732',
"packagecategoryname":"Azure AD"
};
var decodedContent = `export const msalConfig = {
auth: {
clientId: "%Tenantid%",
authority: "https://login.microsoftonline.com/common",
redirectUri: window.location.origin,
postLogoutRedirectUri: window.location.origin,
},
cache: { cacheLocation: "localStorage", storeAuthStateInCookie: false };`
Object.entries(parameters).forEach((element) => {
const [key, value] = element;
console.log(key,value);
if (decodedContent.includes("%"+key+"%") === true) {
console.log("coming inside if");
var newContent = decodedContent.replace("%"+key+"%",value)
console.log(newContent);
}
});
In the decoded content, there is a placeholder %Tenantid%, which I am trying to replace with the correct ID. Instead of a JSON object, the parameters are now coming from an API response, like this:
var parameters =[
{
'Tenantid': 'a5462b57-a249-4778',
"packagecategoryname":"Azure AD"
}
];
My code does not work when the parameters are in an array object.
How can I extract the key and value from an array object, like having the key as "%tenantid%" and the value as the ID "a5462b57-a249-4778"?