Verify if value exists in an array

Hi! My question is related to how we can verify if a value exists in an array without using loops like other normal languages in order to avoid elevated gas costs.

For example I provide an array of addresses and I need to check if an specific address its included in this array.

arrayOfAddress = [address1,address2,address3];

address addressToFound  =  someRandomAddress;

addresToFound exists in arrayOfAddress ??

Thanks

Hi @lucaszanek

Please avoid to post the same question in different threads :slight_smile:
I always read all of them so you will surely get an answer.

The only way to check if a specific address its included in an array [of addresses] is to iterate the array. No other option.

Happy learning,
Dani

As I understand it, calling for data from the blockchain is free. So, no extra gas expenses for iterating through an array, because we do not change any, or store additional, data. Therefore “only” higher execution time with array iterations. Mappings are our friend whenever possible. Is that correct @dan-i ?