I am running a dataviewjs code that displays all the tasks in a note (“noteA”) and all the notes that are linked to it (“noteA”). This is the code I am running:
```dataviewjs
const first = dv.current().file.name;
dv.taskList(dv.page(first).file.tasks
.where(t => !t.completed));
const notes = dv.current().file.outlinks;
for (let note of notes) {
if(dv.page(note).file.name != first){
let ntask = dv.page(note).file.tasks.where(t => !t.completed);
if(ntask.length > 0) {
dv.taskList(ntask);
}
}
}
```
This works but if I insert a image/picture in the note (“noteA”), the dataviewjs code breaks with error showing:
Evaluation Error: TypeError: Cannot read properties of undefined (reading 'file')
How can I tell the code to avoid image links in the for loop?
Using const will make the variable constant. And so if you change the name of the note, then you will always have to reload the dataviewjs for the code to work. So, change all const to let.
The code looks like this now:
```dataviewjs
let first = dv.current().file.name;
let firstTask = dv.current().file.tasks.where(t => !t.completed)
if(firstTask.length > 0) {
dv.taskList(firstTask);
}
let notes = dv.current().file.outlinks.where(x => !x.path.endsWith("png"));
for (let note of notes) {
if(dv.page(note).file.name != first){
let ntask = dv.page(note).file.tasks.where(t => !t.completed);
if(ntask.length > 0) {
dv.taskList(ntask);
}
}
}
```