0

Some days ago, Cherniv gave to me this tip:

var name = "Nora";
var names:Array = ["Mary", "Porter", "Nora", "Flint", "Elsa", "Clair",...];

if( names.indexOf( name ) > -1 )
{
// Success
}

Now, I can't check the existence of "Nora" in this array:

var names:Array = [{label:"Mary"}, {label:"Porter"},{label:"Nora"}, ...];

I'll appreciate any help.

Cheers.

UPDATE:

Now it's working. I did use:

for each (var obj:Object in list)
{
    if (obj.label == compList.text)
    {
        updateList = 1;
        break;//stops the loop;
    }
}
if (updateList == 1)
{
    removeCompany();
}
else
{
    var nativeAlert:NativeAlert = new NativeAlert();
    nativeAlert.alert("You can't update the name!");
}

Is this OK or is an ugly solution?

Thanks

1 Answer 1

3
for each( var obj : Object in names )
{
    if( obj.label == "Nora" )
    {
    // Success;
       break;//stops the loop;
    }
}

I can make it more complex/flexible if you wish.

Sign up to request clarification or add additional context in comments.

5 Comments

may I add a call to a function just before the break?
yes! you can remove the break so each time it finds "Nora" it calls that function. Your example was made for only the first time it finds "Nora".
@Sergio If the answer satisfies your question, please accept the answer. thank you!
I did need just to find the first one only and delete it from the array. I did get it working but I'd like to know if the piece of code is OK or there are a better way. Please, see the UPDATE. Many thanks.
its fine, add a var updateList : Number = 0; before the loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.