IndexOf javascript中的关联数组

时间:2016-11-10 22:03:04

标签: javascript key associative-array indexof

有人可以告诉我如何获取关联数组的索引吗?

例如key的索引:“。launchPad-plankovy”??

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

1 个答案:

答案 0 :(得分:3)

使用ES6,您可以像这样使用findIndex()

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)