【问题标题】:IndexOf an associative array in javascriptjavascript中的关联数组的IndexOf
【发布时间】:2017-03-25 01:59:33
【问题描述】:

谁能告诉我如何获取关联数组的索引??

例如键的索引:“.launchPad-plankovy”??

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

【问题讨论】:

    标签: javascript key associative-array indexof


    【解决方案1】:

    使用 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)

    【讨论】:

      猜你喜欢
      • 2015-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-09
      • 1970-01-01
      • 2013-02-01
      • 1970-01-01
      相关资源
      最近更新 更多