This is the result I am getting from my database when I do a query:
[
{
"name": "file1.txt",
"id": 1,
"file_path": "./public/files/file1.txt"
}
{
"name": "file3.txt",
"id": 3,
"file_path": "./public/files/file3.txt"
},
{
"name": "file4.txt",
"id": 8,
"file_path": "./public/files/file4.txt"
},
{
"name": "file5.txt",
"id": 7,
"file_path": "./public/files/file5.txt"
}
]
And what I want to print is this kinda of format of file path ./public/files/file1.txt
This is what I am trying right now but it doesn't seem to work:
var paths = [];
if(result.length > 0) {
var tmp_path = result[0].file_path
var count = 0
result.forEach(element => {
count++
tmp_path = element.file_path
paths.push(decodeURI(tmp_path))
})
console.log(JSON.stringify(paths,null,4))
}
The result I get is this:
[
"./public/files/file1.txt",
"./public/files/file3.txt",
"./public/files/file4.txt",
"./public/files/file5.txt",
]
Isn't decodeURI() the function I am supposed to use in this case?
I am working on Node.js with router and ejs npms. So this is part of a get function and the result will be populated in front-end with ejs. So what I am trying to do is to pass the correct format on the result which is PATHS