To anyone reading this, I'm a beginner in JavaScript, and I would be grateful for any help regarding the JS transformer I am trying to write.
Basically, I have an array of objects that each have the same format of product information. Each object is a new part with a different manufacturing part number, or MPN (a string). Most of the MPN's are filled out correctly, but occasionally there will be one that is displayed in scientific notation instead( eg. instead of Displaying 100000, it will show 1.00000E5).
The objective of the Transformer is to go through all of the MPN's and look for the ones that contain a ' . ' as the second character and an ' E ' as the second last character. Then when those are found to replace them with the same thing, not in scientific notation.
const data = {{new_bom_query.data.bom.parts}};//this is referencing the array without defining which index of the array
for (let index = 0; index < data.length; index++) {//iderates through all objects in the array
const MPN = data[index].mpn;
var re = new RegExp("/^.*(.)(?=.*E).*/gm");//not sure if this RegEx is correct
if (re.test(MPN) = true) {
MPN.replace(/[^0-9]/g, '');//if the test is true then delete everything thats not a number
}
}
return data
The first photo is how I access the array to display the table shown in the second photo. As you can see many of the MPN's are containing letters and numbers, but the bottom one is a scientific notation.
For some extra details, the query I'm using called new_ bom_query has one object in it called data, which has an object called bom, which has an array called parts, which contain hundreds of objects containing the individual mpn's
I see, your response, data within the transformer, is an object but forEach is an Array method. I probably should have noticed that earlier. I'm still learning.
You can run the forEach on data.bom.parts. Hopefully I didn't miss anything again.