Getting a result of an if statement from a list.

So, i have a list of items like so

    var itemList = new Item[40];
    class Item {
    var itemName : String;
    var PrereqItem1 : String;
    var PrereqItem2 : String;
    var sellPrice : int;
    var weight : float;
    var quantityInInventory : int;

And in a seperate file i have a function which, on fired, i would like to return the value of an item based off the two items the player has selected. So far the function looks like this:

function SearchList(){

for (var i : int = 0; i < Inv.itemList.length; i++) {

	if (item1 == Inv.itemList.PrereqItem1 && item2 == Inv.itemList.PrereqItem2){
	Result = Inv.itemList.itemName;


So, as an example, the player might select a fish (item 1) and a pizza (item 2), and click the button. The code will then search the list for an item that has both the prerequisites of pizza and fish, then return the name of “fish pizza”.

My issue is that i cannot work out how to word the if statement so it…well…works. I suspect the answer is simple, but i’m currently staring at the wood and wondering where the trees are.

Any help you guys can give will be much appreciated.

The typical solution would be to return null if something is not found:

function SearchList() : String {
	for (var i : int = 0; i < Inv.itemList.length; i++) {

		if (item1 == Inv.itemList_.PrereqItem1 && item2 == Inv.itemList*.PrereqItem2){*_

_ return Inv.itemList*.itemName;
return null;
You can then check for null as the return value to see if the function succeeded or failed._