SaaS Developer   
   About    Testimonials    Contact   

Searching for element's index number in Array

While learning Arrays today, I needed a search function which could find any element in an Array and return its index number.

function find(arr, value){
    for (var i=0;i<arr.length;i++){
        if (arr[i] === value){
            return i;
        }
    }
    return -1;
}

var abc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];

alert( find(abc,'q') );

BTW, to create this very long Array I used JavaScript too.

Check out the result function with a very long Array here, or below by clicking “Result”:


comments powered by Disqus