Array.find is not working on a 2d array in ionic3?


#1

I have to find clicked id inside the 2D array and i have tried with find function but its not working as expected i have attached my console image tell me anyone how to fix this?

  var matchedObject = self.selectedSubCategoryArray.find(x=>x === category.keyId);


#2
  1. what is category.KeyId?
  2. you trying to loop throw object not array.
  3. please give more information about what are you trying to do.

#3

sir,category.keyId is get after click on the categoryTab and i have to search this category.keyId on a selectedSubCategoryArray if exist get the matched object but here arrray is 2dArray?


#4

Ok, Solution is:

let matchedObject = [];
for(let key in self.selectedSubCategoryArray) {
    if (key == category.keyId) {
        matchedObject.push(self.selectedSubCategoryArray[key]);
    }
}

#5

its working sir thanks a lot.
sir how to find the index of 2D array indexOf is not working ?