根據數組對象的某個屬性值找到指定的元素


1.現在有一個數組對象,也就是數組元素是對象類型,現在的需求是根據對象的某個屬性值,找到該數組對應的元素(對象),比如根據"bianma"=="11",找到對應的"name"為"商品房" : 

該數組對象數據如下: 

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.判斷是否有某一項

var isDelStorage = this.proRoleAll.findIndex((v) => {
	return v.ruleId == this.nowId;
});
如果沒有,就返回-1

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM