Im having problem with getting splice to work for my /home.
Im clearly doing something wrong but I cant figure out what, please help?
const logArray = [
"|timestamp |url |userid|",
"|2019-03-01 09:00:00UTC |/contact.html |12345 |",
"|2019-03-01 09:00:00UTC |/contact.html |12346 |",
"|2019-03-01 10:00:00UTC |/contact.html |12345 |",
"|2019-03-01 10:30:00UTC |/home.html |12347 |",
"|2019-03-01 11:00:00UTC |/contact.html |12347 |",
"|2019-03-02 11:00:00UTC |/contact.html |12348 |",
"|2019-03-02 12:00:00UTC |/home.html |12348 |",
"|2019-03-03 13:00:00UTC |/home.html |12349 |",
""
];
let result = [];
const urls = () => {
const url = logArray.map((Objects, index, arr) => {
return Objects.slice(25, 38);
});
console.log("url:", url);
if (url) {
const contact = url.find((a) => a.includes("contact"));
result.push(contact);
console.log(contact);
//console.log(contact)
}
if (url) {
const home = url.find((a) => a.includes("home"));
result.splice(3, 0, home);
console.log(home);
}
};
urls();
console.log(result);
and I have counted the unique user ids on each url and no. of visits on each url.
So I get this array back, no splice at all?!:
console.log("result:", result); //output ["/contact.html", "/home.html ", 5, 4, 1, 1]
this is what I would like it to look like:
// dream scenario: ["/contact.html", 5, 4, "/home.html", 1, 1]
When I take the splice function out of the code and try it in codepen it works fine....but not in the fully code
In my opinion, this isn't the best variant to parse log data but if you want. That's solution