I am working with some xml files stored on S3. I use the xml2js module in Node to parse the xmls and then I extract the strings that have .jpg in them. I was using the filter method and then tried using my own for loop but that didn't shave any time off. Is there any faster way to write this section of the code or is this the fastest way to get it done. Any help appreciated.
using filter method:
//this took 52393ms
var file = JSON.stringify(data);
var arrayOfStrings = file.split('"');
var images = arrayOfStrings.filter(function(str) {
return str.indexOf('.jpg') !== -1;
});
resolve(images);
using for loop:
//this took 52681ms
var file = JSON.stringify(data);
var arrayOfStrings = file.split('"');
var images =[];
for(let i = 0; i < arrayOfStrings.length; i++) {
if(arrayOfStrings[i].indexOf('.jpg') !== -1) {
images.push(arrayOfStrings[i]);
}
}
resolve(images);
data looks like the following after I use file.split('"');
[ '{','rstuv',':{','options',':[{','']];