Dataviewjs include() method doesn't work with frontmatter list of links

What I’m trying to do

I’m trying to count the amount of same list property values among the pages.
All pages have list property (called Notes), it is a list of links to created or not created pages (for example - [[aquamor]]).

Things I have tried

Having read the forum, I’ve tried this code


//perfume is an array on 2 items - pages with fronmatter Notes
//Notes is a list of links, both pages have Notes[0]="[[aquamor|aquamor]]"
const perfumes = dv.pages('"нос"').where(f => f.Author=="horhehe");

let saved1, saved2;

//saved1 is a first note of perfume 1
saved1 = perfumes[0].Notes[0];
//saved2 is a first note of perfume 2
saved2 = perfumes[1].Notes[0];

//lets print our notes
dv.paragraph("saved1 = "+ saved1);
dv.paragraph("saved2 = "+ saved2);
//the outcome is two links both named aquamor

//lets compare these two notes we have
dv.paragraph("are they the same? "+(saved1 == saved1));
//the outcome is true, so they are the same

//however for this two inclusion checks 
//the outcome should be true and true as I understand it
dv.paragraph("is aquamor in perfume 1? "+perfumes[0].Notes.includes(saved1));
dv.paragraph("is aquamor in perfume 1? "+perfumes[0].Notes.includes(saved2));
//but the outcome is true and false


it produces this outcome
image

I can’t understand, why the last output is false (and how to write a code where the outcome of checking if a link property is included will be true)

found a typo, right code is below


//perfume is an array on 2 items - pages with fronmatter Notes
//Notes is a list of links, both pages have Notes[0]="[[aquamor|aquamor]]"
const perfumes = dv.pages('"нос"').where(f => f.Author=="horhehe");

let saved1, saved2, test;

//saved1 is a first note of perfume 1
saved1 = perfumes[0].Notes[0];
//saved2 is a first note of perfume 2
saved2 = perfumes[1].Notes[0];

//lets print our notes
dv.paragraph("saved1 = "+ saved1);
dv.paragraph("saved2 = "+ saved2);
//the outcome is two links both named aquamor

//lets compare these two notes we have
dv.paragraph("are they the same? "+(saved1 == saved2));
//the outcome is false, so why

output:
image

But I still cant understand why the last outcome is false

You can’t just compare links like that. Try the following in a file of its own:

[[Something]]

[[Something|someone]]

```dataviewjs

const outlinks = dv.current().file.outlinks 
dv.paragraph(outlinks)
dv.paragraph("object vs object: " + (outlinks[0] == outlinks[1]) )
dv.paragraph("link.equals(): " + outlinks[0].equals(outlinks[1]))
```

So in your case it should suffice to do saved1.equals(saved2).

1 Like

got it! thank you sm

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