var siteList = {};
var siteInfo = [];
var part_str = '[{"part":"00000PD","partSupplier":"DELL"}]';
var part = part_str.substring(1,part_str.length-1);
eval('var partobj='+part );
console.log(partobj.part);
console.log(partobj.partSupplier);
The code above is functioning properly.
My task now is to compare the part number with a specific value. If they do not match, the partSupplier
will be added to the JSON data; otherwise, it won't.
if (partobj.part.includes("00000PD")){
var partSupp= partobj.partSupplier;
} else {
partSupp= "HP";
}
siteInfo = {
"Parts_Num": part,
"partSupplier": partSupp
}
siteList.siteInfo.push(siteInfo);
I attempted the following approach, but the partSupplier
field remains empty:
if (partobj.part.includes("00000PD")){
var partSupp = [partobj.partSupplier];
console.log('partSupp' || partSupp);
} else {
partSupp = "HP";
}
The output from the console:
partSupp
No value is being returned.
I am utilizing console.log for testing purposes before finalizing the code.