Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Combine multiple "equals … or"

  var group = 4;
  var level = [1,2];
  var options = 'ng;nk';

  var arrayWithCorrectGroup = shuffledArray.filter(innerArray => innerArray[0] === group);
  var arrayWithCorrectLevels = arrayWithCorrectGroup.filter(x => x[1] === level[0] || x[1] === level[1] );
  var arrayWithCorrectValues = arrayWithCorrectLevels.filter(x => x[3].includes(...options.split(';')));

When using .includes as seen in arrayWithCorrectValues, you can use the three dots to loop through all options in the array. I want to know if there is a similar way for the equals or in the arrayWithCorrectLevels. It’s possible to have an array with 10 levels. I don’t want to write x[1] === level[n] ten times.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

There are several ways to check if x[1] is equal to any element of the level array.

Example one:

level.includes(x[1]);

Example two:

level.some(item => item === x[1]);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading