0 votes

I have a pretty big array with unique values from which I need specific values pretty often. The obvious way to do this (at least obvious to me) is:

for value in myarray:
if value == specific
value:
return value

If my specific value is at position x , this needs x steps to find it. Simple.

But I also happened to stumble across the find() function in array. So I thought of another way:
var neededvalueindex = myarray.find(specificvalue)
var neededvalue = myarray[neededvalueindex]
return needed_value

I guess there are even more ways to achieve what I want, but what I would really like to know, is how I find an efficient (possibly the most efficient) one.
I appreciate any advice on the matter.

in Engine by (55 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.