List children with name in array?

Ok I’ve been trying to do that the whole day and I can’t get it to work. x’D

I don’t have one specific code cause I tried countless variations I found on google and unity answers and none were exactly what I was looking for. I refrained from asking sooner cause I thought I’d find it and cause I’m asking stuff here basically every couple days. xD

I have an object and a script on it and all I want is for it to find its children named “Laser”, and put them in an array, cause I want to destroy them, or deactivate their particle emitter, in another function when something happens.

How can I do that?

EDIT: Thank you all for all the answers it really means a lot!

A JS Example:

#pragma strict

import System.Collections.Generic;

var Lasers : List.<Transform>;

function Awake()
{
	for(var t : Transform in transform)
	{
		if(t.name == "Laser")
			Lasers.Add(t);
	}
	Debug.Log(Lasers.Count);
}

function Update()
{
	if(Input.GetKeyDown(KeyCode.E))
	{
		if(Lasers.Count > 0)
		{
			Lasers.RemoveAt(0);
		}
		else print("No more items in list.");
		print(Lasers.Count);
	}
}

Try something like this.

import System.Collections.Generic;

#pragma strict

var objectName : String = "Laser";

//parent object transform
var parent : Transform;

// list (array)
var myList : List.<Transform> = new List.<Transform>();

function FetchObject(){
	
	// loop through all the child transforms of the parent.
	for (var child : Transform in parent) {
	
		//if the child transform name is same as wanted, add it to the list(array)
	    if(child.name.Equals(objectName)){
	    	myList.Add(child);
	    }
	    
	}

}

function ProcessObject(){

	//myList[0].GetComponent(anycomponent).dosomething;

}

You can use a generic collection. I have used list, you can use anything you like.

You can either manually reference them in an array in a prefab of your object, or use:

for(var childObj in transform){
  if(childObj.name=="Laser")
    //do things
}

I’d recommend the former since getting gameobjects by their name can be unreliable.