Need help with this dataviewJS code: `.file.outlinks` displaying duplicates of the same note

I wrote this dataviewJS code after multiple trials and errors (link1 and link2) and I am kind of tired now after many hours on this… Everytime I think I am close to the being done, a new question appears… >.<

I want to make a simple task list that shows all the tasks from the note and all it’s outlinked notes.

But executing the following code, what happens is that if I link a note twice in my main note, that note gets displayed twice in the dataview Query (because of the line dv.current().file.outlinks displaying two instance of the same note.)

How can I prevent .outlinks from displaying multiple duplicate instances of the same file?
Any help will be greatly appreciate… I am really on the edge of giving up now…

Here’s the code for reference:

```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);
		}
	}
}
```

Found this answer and used it in my code to get unique values from the outlinks.

changing the line:

let notes = dv.current().file.outlinks
.filter((value, index, self) => index === self.findIndex(t => t.path === value.path))
.where(x => !x.path.endsWith("png"));

This solves the problem.

Another way of doing this is with indexOf() to find the unique outlinks and push only those to an array object which then you can use to show in the taskList()

```dataviewjs
// printing tasks from current note
let first = dv.current().file.name;
let firstTask = dv.current().file.tasks.where(t => !t.completed);
(firstTask.length > 0) && dv.taskList(firstTask);

// getting all outlinks without .png and current note
let notes = dv.current().file.outlinks.where(x => !x.path.endsWith("png") && x.path != dv.current().file.path);

// get only the unique outlinks wish indexOf()
let paths = notes.map(x => x.path);
let unique = [];
paths.map(x => (unique.indexOf(x) === -1) && unique.push(x));

// printing tasks from all unique outlinks
let tasks = unique.map(x => dv.page(x).file.tasks.where(t => !t.completed));
tasks.map(x => x.length > 0 && dv.taskList(x));
```

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.