Remove current file.link from array

For my movie database, I’ve got notes for actors and notes for movies.

In the movie-note I mention all actors in a particular movie in YAML, using the list-property.

In the actor-note I’ve got a dataviewjsquery set up, where (per movie) I show title, publication date and actors.

I would like to exclude the current actor from the list and then show “plays with … {rest of array}”

The current query is this:

dv.table(["Icon", "Poster", "Title", "Actors", "Date of Publication"], dv.pages('"Movies"')
  .where(p => dv.func.contains(p.actors, dv.current().file.link))
  .map(p => [
    p.Icon,
	p.posterLink,
	dv.fileLink(p.file.path, false, p.title),
	p.actors,
	p.date_publication
   ])
);

I’ve tried using p.actors.filter(a => a.actors !== dv.current().file.link, but then it still shows the current actor. I’ve checked actors via typeof and it’s an array.

I know I can get the first mentioned actor via actors[0], but how can I exclude dv.current().file.link from this array?

You said p.actors.filter(a => a.actors !== dv.current().file.link), but here you’re looking at each actors internal field actors… Is that present?

Shouldn’t this be: p.actors.filter(a => a !== dv.current().file.link)?

Hi @holroy , you’re probably right, since there’s no actors -field inside actors.

I’ve tried using your suggestion, but unfortunately this still shows the current actor (aka current file name/link).

Have you tried p.actors.filter(a => a.path !== dv.current().file.link.path)

I had to do something similar and the below filters out the current page from the connections property

dv.table(["File", "Other connections"],
    dv.pages("-#kb-article")
    .where(p => dv.func.contains(p.connections, dv.current().file.link))
    .map(b => [b.file.link, b.connections.filter(p => 
        p.path !== dv.current().file.link.path
    )])
)

There was something not right in my previous post, and the post by @Dave_PR further enhanced this feeling. Then I remembered that you can’t compare links directly in dataviewjs, you need to use the .equals() function. (Or compare a subpart like the file.path)

So try using p.actors.filter(a => !a.equals(dv.current().file.link))

1 Like