Dataviewjs does not parse logical 'AND' &&

Things I have tried

Please note that I don’t know javascript. I managed to patch the code after multiple google searches so I apologize if there is something rather obvious that I’m overlooking.
I tried all possible bracket combinations but each time it yields the same error. When I omit the brackets containing both the return statements it yields (Unexpected Identifier return) and when I omit any one of them it simply yields (Unexpected Identifier) Tried Omitting the first colon as well but to no avail.

What I’m trying to do

I wanted to filter a query in dataviewjs using multiple conditions so I used the following syntax:

$=dv.list(dv.pages('"Personal Space/Documentations"').sort(f=>,"desc").filter(function(f) {{return'Index') === -1}; && {return'windows-commands') === -1;}}))

However, it returns the following:

Dataview (for inline JS query 'dv.list(dv.pages('"Personal Space/Documentations"').sort(f=>,"desc").filter(function(f) {{return'Index') === -1;} && {return'windows-commands') === -1;}}))'): SyntaxError: Unexpected token '&&'

Your query does not need to be a inline query.
If you use a regular DataviewJS codeblock you can spot errors easier.

If we take your code and format it properly:

dv.pages('"Personal Space/Documentations"')
	.sort(f =>,"desc")
	.filter(function(f) {
		return'Index') === -1};
		 return'windows-commands') === -1;

we can see a few problems.

  • the {return ...}; syntax is not valid
  • the filter function does not return any value

Here is some valid code:

		.sort(f =>,"desc")
		.filter(f => {
			return'Index') === -1
			&&'windows-commands') === -1;}

@joethei Ah man, you just beat me to it. I figured out a solution of my own by using the intersection of two different arrays.

var x = dv.pages('"Personal Space/Documentations"').filter(function(f) {return f.file.path.indexOf('windows-commands') === -1;})
var y = dv.pages('"Personal Space/Documentations"').filter(function(f) {return'Index') === -1})
var intersection1 = y.filter(value=>x.includes(value))

and then passing dv.list on intersection1. My solution may not be the best, but it works for now. Thanks for your reply.

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