Is there a way to get indexOf on this array?
var myArray = new Array(
{title: "Test1", id: "Header1", html: "Header1", style: "background-color: red; color: white;"});
James
22.4k5 gold badges30 silver badges44 bronze badges
asked Oct 26, 2011 at 20:53
Todd Vance
4,7417 gold badges50 silver badges67 bronze badges
2 Answers 2
If you want to be able to do a search for that object, if you have the same reference, sure.
var o = {"foo": "bar"};
var a = [o];
alert(a.indexOf(o));
But this won't work:
alert(a.indexOf({"foo": "bar"}));
answered Oct 26, 2011 at 20:58
Alex Turpin
47.9k23 gold badges118 silver badges146 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Gergely Fehérvári
ehh. i wouldn't figured this out by myself!
This is what I did to make it work -- but it's not pretty:
//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();
This was all just to make my Sencha carousel look right when clicking buttons, but now I realize that if someone slides it manually that it wont set the currentCarouselIndex... bleh, this is a lot of work just to make it look a little better.
answered Oct 26, 2011 at 21:37
Todd Vance
4,7417 gold badges50 silver badges67 bronze badges
Comments
lang-js
new Array({a:'a',b:'b',c:'c'},{a:'d',b:'e',c:'f'})associative array is not array, this is an obj:associative = {a:'a',b:'b',c:'c'}