IndexOf an associative array in javascript

can someone tell me please how to get index of an associative array??

for example index of key:".launchPad-plankovy"??

        var droppableClasses = [
           {key:".stackDrop-plankovy", value:".card-plankovy"}, 
           {key:".launchPad-plankovy", value:".card-plankovy"}
        ];

Upvotes: 0

Views: 2006

Answers (1)

Nenad Vracar
Nenad Vracar

Reputation: 122047

With ES6 you can use findIndex() like this.

var droppableClasses = [{
  key: ".stackDrop-plankovy",
  value: ".card-plankovy"
}, {
  key: ".launchPad-plankovy",
  value: ".card-plankovy"
}];

var index = droppableClasses.findIndex(function(e) {
  return e.key == '.launchPad-plankovy';
})

console.log(index)

Upvotes: 3

Related Questions