Post

2 followers Follow
0
Avatar

filter arrays

var AR1 = @all of array 1;  (= [true, false, true, true])

var AR2 = @all of array 2 ; (= [text1, text2, text3, text4])

 

What I want is to show only the text-values of array 2, when array 1 is "true":

  • text1
  • text3
  • text4

 

How do I do this? Maybe a loop, or filter-function?

Wichard Hulsbergen

Please sign in to leave a comment.

3 comments

0
Avatar

Not too much action here... 

 

Anyway I am a bit further:

var status = @All of Status        (["actief", "non-actief", etc])
var bhmID = @All of ID_bhm    (["BHM001", "BHM002", etc])
var bhm_select = []
var i;

for(i = 0; i < bhmID.length; i++) {
if(status [i] == "actief"){
bhm_select.push(bhmID[i]);
}
}
bhm_select.join("\n");

 

This seems to work, but gives the error "invalid value "BHM001\n"(string) : must be number"

The error seems to come from the if-statement. If I remove that and in fact copy array bhmID, all is well.

 

Starting a new calculated field doesn't work. What am I doing wrong?

Wichard Hulsbergen 0 votes
Comment actions Permalink
0
Avatar

Hello Wichard,

if you can save the template and if the calculation field (in item view) shows the correct result - ignore that error notification, your code is correct.. 
Takes too long to explain it here, but the calculation field sandbox which produces the preview is a bit picky (or: sensible). It awaites a number as result - and returns the notification. I see that rather often. 

Rainer

Rainer Grabowski 0 votes
Comment actions Permalink