How to write an (if) statement in (map) function in dataviewjs

Instead of doing an if in the lambda function of map(), trying do a function call with the k.status as the parameter.

In other words make a function before your code:

function mapIcon(status) {
  if (status == "Active")
    return "A"
  else if (status == "Idle") 
    return "I"
  else
    return "?"
}

and let the .map be something like:

.map( k => k.symbol + " " + k.file.link + mapIcon(k.status) )

Code is untested and could surely be optimised, but the gist of it should be correct, and allow you to do whatever related to the k.status value.

Regards,
Holroy

1 Like