jquery - JavaScript find matching object in an array of objects -


hi have array of objects

[        {          outletid: 619734          tleaderid: "3f8be9bf-5920-4d3d-b915-50ca76cb21oo"        },        {          outletid: 619755          tleaderid: "3f8be9bf-5920-4d3d-b915-50ca76cb24ty"           },        {          outletid: 619700          tleaderid: "3f8be9bf-5920-4d3d-b915-50ca76cb2qwe"          }        // , on... ] 

then i'm creating object

[        {          outletid: 619734          tleaderid: "3f8be9bf-5920-4d3d-b915-50ca76cb21oo"        } ] 

and want find if new created object matches of object in array. tried no luck

$.each(objcollection, function () {       if (this === newobject) {          alert("already exist!!!");       } }); 

any idea?

thanks in advance

if i've understood question correctly, want demo ?

var array = [{     outletid: 619734,     tleaderid: "3f8be9bf-5920-4d3d-b915-50ca76cb21oo" }, {     outletid: 619755,     tleaderid: "3f8be9bf-5920-4d3d-b915-50ca76cb24ty" }, {     outletid: 619700,     tleaderid: "3f8be9bf-5920-4d3d-b915-50ca76cb2qwe" } // , on... ]  var newarray = [{     outletid: 619734,     tleaderid: "3f8be9bf-5920-4d3d-b915-50ca76cb21oo" }];  function matchcase(array1,array2){      var matchfound = false;      (var = 0; < array1.length; i++) {          item = array1[i];          if (item.outletid === array2[0].outletid && item.tleaderid === array2[0].tleaderid) {              matchfound = true;             break;          }     }      return matchfound;  }  console.log(matchcase(array,newarray)); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -