What I’m trying to do
I want to add the current file path at the end of a list of its outlinks paths (or at the start)
example: test1
is the current note, test2
and test3
are the outlink notes. What I want in the final array:
- test2.md
- test3.md
- test1.md
Things I have tried
this is the code I ran that gives the error: “notes.push is not a function
”:
```dataviewjs
// get all outlinks paths
let notes = dv.current().file.outlinks
.map(x => x.path);
// push current path to notes
notes.push(dv.current().file.path);
// print notes
dv.paragraph("printing:");
dv.paragraph(notes);
```
I have checked and confirmed that notes
is an array:
dv.paragraph("is this array:");
dv.paragraph(dv.isArray(notes));
I have also tried to see what happens if I ran dv.array(notes)
function and then ran notes.push()
which still outputs the same error.
For now, I found a workaround is to create an empty array and push the elements of notes and then push the current file path:
```dataviewjs
// get all outlinks paths
let notes = dv.current().file.outlinks
.map(x => x.path);
// create empty array
let arr = [];
// push notes element to empty array
notes.map(y => arr.push(y));
arr.push(dv.current().file.path);
// print array
dv.paragraph("printing:");
dv.paragraph(arr);
```
My question:
Why can .push() work for an array but not another?