js怎么获取数组中元素的位置
var a=new Array({key:'1',value:"a"},{key:'2',value:"b"},{key:'3',value:"c"},{key:'4',value:"d"});
下面写了个例题
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function Map( ){
this.elements = new Array();
this.init = function( _e ){
this.elements = _e ;
}
this.put = function(key, value) {
// 加入元素
this.elements.push({key: key, value:value});
}
this.getByValue = function( _value) {
// 取出对应value
try{
for (i = 0; i < this.elements.length; i++) {
if (this.elements[i].value == _value) {
return this.elements[i].key;
}
}
}catch(e) {
return null;
}
}
this.getByKey = function( _key) {
// 取出对应key
try{
for (i = 0; i < this.elements.length; i++) {
if (this.elements[i].key == _key) {
return this.elements[i].value;
}
}
var value = "b";
var map = new Map();
map.init( a );
alert( map.getByValue( value ) );
//-->
</SCRIPT>
</BODY>
</HTML>
document.write(sz.indexOf(45))
var a = arr.indexOf(num);
return a;
}