1.如今有一個數組對象,也就是數組元素是對象類型,如今的需求是根據對象的某個屬性值,找到該數組對應的元素(對象),好比根據"bianma"=="11",找到對應的"name"爲"商品房" : javascript
該數組對象數據以下: java
var datas = [ { "name": "商品房", "bianma": "11" }, { "name": "商鋪", "bianma": "12" } ]
咱們能夠經過對數組進行篩選操做:數組
var data= datas.filter(function(item){ return item.bianma == "12"; }) console.log(data); // [{name: "商鋪", bianma: "12"}]
2.判斷是否有某一項this
var isDelStorage = this.proRoleAll.findIndex((v) => { return v.ruleId == this.nowId; }); 若是沒有,就返回-1