Get the last element in a list

What I’m trying to do

I have a file.tag property that holds the type of the particular note. This tag is nested like below.

I’m trying to use DataView create a table with the file’s type i.e. the deepest tags - audio, book, MoM, etc.

Things I have tried

split(file.etags[0],"/")[2] AS "Type"

This is how I’m currently getting the final type, but I would like to,

  1. Get the last element of the array directly so that I wouldn’t get a null incase the type contained only 1 level of nesting.
  2. (Bonus doubt but not very important) If there happened to be a note that contains two tags, I need to get the last elements of both.

So, for each tag in a file you want to get the deepest level of that tag?

  • With map() you can perform an operation for each element of an array.
  • With split(<tag>, "/") you can create an array with all the levels of a tag, in order.
    • As you’ve noted, the last element of the array will be the deepest level. A trick to get the last element of an array is slice(<Array>,-1)[0]

Putting it all together:

map(file.etags, (tag) => slice(split(tag,"/"),-1)[0])

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