# \[Question\]How to check an array whether if it consist a value

**URL:** <https://forum.kirupa.com/t/question-how-to-check-an-array-whether-if-it-consist-a-value/261735>\
**Category:** Uncategorized\
**Created:** [May 30, 2008, 11:00am UTC](https://forum.kirupa.com/t/question-how-to-check-an-array-whether-if-it-consist-a-value/261735 "2008-05-30T11:00:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vern228](https://avatars.discourse-cdn.com/v4/letter/v/c68b51/32.png) [@Vern228](https://forum.kirupa.com/u/Vern228)\
**Post date:** [May 30, 2008, 11:00am UTC](https://forum.kirupa.com/t/question-how-to-check-an-array-whether-if-it-consist-a-value/261735/1 "2008-05-30T11:00:58Z")

</div>

Here’s an array:

> var myArr:Array = new Array(“January”, “February”, “March”, “April”);

if I want to check whether if “February” is presented in myArr, which returns boolean value,  
how do I write the code?  
I’ve looked into the Flash Help but the array constructer seems don’t have this type of action that fits my need…can anyone help me?:crying:

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [May 30, 2008, 11:41am UTC](https://forum.kirupa.com/t/question-how-to-check-an-array-whether-if-it-consist-a-value/261735/2 "2008-05-30T11:41:20Z")

</div>

there is a tutorial on the front page under flash…

---

<div class="post-metadata">

**Author:** ![jon\_bla](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@jon\_bla](https://forum.kirupa.com/u/jon_bla)\
**Post date:** [May 30, 2008, 1:05pm UTC](https://forum.kirupa.com/t/question-how-to-check-an-array-whether-if-it-consist-a-value/261735/3 "2008-05-30T13:05:46Z")

</div>

```auto

var myArr:Array = new Array("January", "February", "March", "April"); 
var searchStr:String = myArr.toString();
index = searchStr.indexOf("February");
trace(index); // if Febuary is not found : output will be: -1 otherwise a positive number

```

---

<div class="post-metadata">

**Author:** ![Charleh](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@Charleh](https://forum.kirupa.com/u/Charleh)\
**Post date:** [May 30, 2008, 1:33pm UTC](https://forum.kirupa.com/t/question-how-to-check-an-array-whether-if-it-consist-a-value/261735/4 "2008-05-30T13:33:02Z")

</div>

Forgive me if I’m wrong but isn’t that a bit of a buggy search implementation jon? Given an array with the following elements

{“Bob”, “Ethan”, “Paul”}

Your method will return a positive number on a search for ‘B,eth’

Ok so it’s not a likely scenario but it’s still a possibility imagining a user typing in some value and hitting the wrong key

I would go for something more solid such as

```auto

function arraySearch(search:String, arr:Array):Boolean {
  for (var i = 0; i < arr.length; i++) {
    if(arr* == search) {
      return true;
    }
  }
 
  return false;
}

```

Usage

```auto

 
if(arraySearch("SomeValue", someArray)) {
 // Do something
}

```

---

<div class="post-metadata">

**Author:** ![Vern228](https://avatars.discourse-cdn.com/v4/letter/v/c68b51/32.png) [@Vern228](https://forum.kirupa.com/u/Vern228)\
**Post date:** [May 30, 2008, 4:13pm UTC](https://forum.kirupa.com/t/question-how-to-check-an-array-whether-if-it-consist-a-value/261735/5 "2008-05-30T16:13:44Z")

</div>

oh wow~!thanks all~I think i get it!  
Actually i forgot that there’s a tutorial on kirupa…thanks for remind, randomagain~
