SID-02402: Look up for item in array
| Status: |
Answered |
TWiki version: |
|
Perl version: |
|
| Category: |
CategorySearch |
Server OS: |
|
Last update: |
6 years ago |
Which command or code could best be used to find out whether an item is found in an array or not?
Example: Given an array "Fruit" (strawberry, apple, pear, watermelon, kiwi, mango).
Is "kiwi" in this array? --> True
Is "banana"in this array? -->False
I was looking in
SpreadSheetPlugin for some Excel-like 'lookup'-command. But what is easiest to use?
--
Emiel Van Riel - 2019-04-25
Discussion and Answer
There are several ways. Here is one:
-
$NOT($EMPTY($LISTIF($EXACT($item, kiwi), strawberry, apple, pear, watermelon, kiwi, mango))) returns 1
-
$NOT($EMPTY($LISTIF($EXACT($item, banana), strawberry, apple, pear, watermelon, kiwi, mango))) returns 0
Try the formua at
SpreadSheetPlugin
--
Peter Thoeny - 2019-04-25
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.