Find unidirectional backlinks efficiently? (inefficient dataviewjs included)

For map of content documents, it would be convenient to show only the backlinks that have not been linked in the document (unidirectional backlinks).
Is there an efficient way to identify these, either within the note or in a pane?

The below Dataviewjs approach works, but it’s long-winded and makes notes look cluttered:

function arr_diff (a1, a2) {
    var a = [], diff = [];
    for (var i = 0; i < a1.length; i++) {
        a[a1[i]] = true; 
    }

    for (var i = 0; i < a2.length; i++) {
        if (a[a2[i]]) { 
            delete a[a2[i]]; 
        } 
    }

    for (var k in a) { 
        diff.push(k); 
    }
    return diff; 
}

var backlinks = dv.current().file.inlinks;
var links = dv.current().file.outlinks;
dv.list(arr_diff(backlinks, links))

It seems like the following should work, but it shows all backlinks (it seems that the filter command doesn’t work as expected in dataview)

var backlinks = dv.current().file.inlinks;
var links = dv.current().file.outlinks;
let unlinked = backlinks.filter(x => !links.includes(x))
dv.list(unlinked)

(I’m a javascript novice and adapted the above from Stack Overflow, so forgive me if the solution is obvious! This would be so easy in Python :slight_smile: )

I’m not sure if I understand (my fault, english isn’t my native language )… but try something like this:

```dataview
LIST
FROM [[#]] AND !outgoing([[#]])
```
2 Likes

Ah yes, that’s just what I was looking for - thank you!!

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