0 votes

Hi, I'm learning Godot script and I was asking myself if it was possible to return a array index from the value in? Idk if I am clear...

For example :

var array
var name

array = ["John", "Mathilde", "Marc", "Sophie"]

name = "John"

How can I find the array[index] from "John"?

in Engine by (15 points)

Are you trying to find the position of a certain element in the array? If so, have you tried the find() function?

1 Answer

+5 votes
Best answer

you can get the index by using the find() array function.


var array = ["john", "maria", "kyle", "jenny"]
var name = "kyle"

onready var index = array.find(name,0) #this will return an index no. or -1 if its not found.

check the godot docs for more details. array docs here

hope this helps!

by (439 points)
selected by

Thank you Dustin and Ertain ! I didn't know the function find(), I will get informations about. It seems it is what I need!

glad we helped! gamers help gamer and thats what makes us gamers.

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.