Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取由Javascript对象组成的Javascript数组的索引_Javascript_Arrays - Fatal编程技术网

获取由Javascript对象组成的Javascript数组的索引

获取由Javascript对象组成的Javascript数组的索引,javascript,arrays,Javascript,Arrays,有没有办法在这个数组上获取indexOf var myArray = new Array( {title: "Test1", id: "Header1", html: "Header1", style: "background-color: red; color: white;"}); 如果您希望能够搜索该对象,如果您具有相同的引用,请确定 var o = {"foo": "bar"}; var a = [o]; alert(a.indexOf(o)); 但这是行不通的: alert

有没有办法在这个数组上获取indexOf

var myArray = new Array(
    {title: "Test1", id: "Header1", html: "Header1", style: "background-color: red; color: white;"});

如果您希望能够搜索该对象,如果您具有相同的引用,请确定

var o = {"foo": "bar"};
var a = [o];
alert(a.indexOf(o));
但这是行不通的:

alert(a.indexOf({"foo": "bar"}));

这就是我所做的,让它工作起来——但它并不漂亮:

//Check to see if we are going to a card that should be right or left.
var rightOrLeft = "left";
var destinationIndex = 0;
for(var i=0; i < dynamicPreezeArray.length; i++){
        if (dynamicPreezeArray[i].id == this.text) {
                  destinationIndex = i;
       };
}

if (destinationIndex < currentCarouselIndex) {
         rightOrLeft = "right";
}

preezer.setActiveItem(this.text,{type:'slide',direction: rightOrLeft});
currentCarouselIndex = preezer.getActiveIndex();   
//检查我们要找的卡应该是右边还是左边。
var rightOrLeft=“left”;
var destinationIndex=0;
对于(变量i=0;i

这一切只是为了让我的Sencha旋转木马在点击按钮时看起来正确,但现在我意识到,如果有人手动滑动它,它将不会设置当前的旋转木马。。。哎呀,为了让它看起来更好一点,这需要做很多工作。

你说的“indexOf”是什么意思?换句话说,你能解释一下你想做的手术吗?数组中只有一个元素,所以它的索引保证为零。只做了一个元素的事情只是为了简洁——我想检查myArray中'Header1'id的索引。因为这是一种关联数组,所以我不确定如何使用array对象附带的indexOf方法。看起来我不能。嗯,它不是一个关联数组——它只是一个数组;就是这样。我不知道有哪种“indexOf”实现允许使用“comparator”函数参数,尽管这是可能的。我不明白,数组包含对象,或者这是一个关联数组?差异:数组cont.objs.:
新数组({a:'a',b:'b',c:'c'},{a:'d',b:'e',c:'f'})
关联数组不是数组,这是一个obj:
关联={a:'a',b:'b',c:'c'}
ehh。我自己也不会想到的!