Array has function

Godot Version

4.3

Question

I have an array of labels. Is it possible to use the has() function to determine if there is a label matching a particular text? Or will I have to use a different type like a dictionary.

The has() function used to determine the child of a node not text, you can use loop and if statement for it.

3 Likes

any(): Array ā€” Godot Engine (stable) documentation in English

3 Likes

var matched_label:Label = label_array.filter(func(l:Label):return l.text == "text I am looking for")

2 Likes

Small correction, @sancho2: filter() returns an Array

1 Like

If you mean an array such as nodes with labels, yes it will work

	var lbl:Array=[$TextureRect/Label, $Label2, $Button2]
	if lbl.has($TextureRect/Label):
		pass

Also this will work win has() and in:

	var lbl:Array=["abc","xyz",1,2]
	if lbl.has("xyz"):
		pass

	if 1 in lbl:
		pass

Thanks everyone for the help. I ended up just using the filter function to narrow it down to the one label Iā€™m interested in.

2 Likes