get array position in javascript
by Ramya[ Edit ] 2010-02-01 09:24:26
get array position in javascript:
Get array position of selected array value in javascript.
var get_pos;
function getPosition(arrayName,arrayItem)
{
for(var p=0;p
if(arrayName[p]==arrayItem){
get_pos = p;
}
}
}
For Example:
var get_pos;
function getPosition(arrayName,arrayItem)
{
for(var p=0;p
if(arrayName[p]==arrayItem){
get_pos = p;
}
}
}
var stock_val;
var numbers = new Array('test','test1','test2');
function verify(){
var tt = getPosition(numbers,'test');
}
getPosition() returns the array position and stores it in the variable "tt". Alert tt to know the array position.