Search code examples
javascriptarraystypescriptlogic

Filter 2-dim array based on string value that contain on 2nd array


so i have a bad bad logic for this assignment, i need to filter 2 Dimension Array that contains the value of string that input on 2nd array.

So this is the example of the 2-Dim Array

const roles = [ ['roles', 'admin', 'write'] ['roles' ,'admin', 'read'] ['roles', 'member', 'read']]

I need to filter the array that only containts 'member' and the result is like this

const result = ['roles', 'member', 'read']

How can i achieve this ?


Solution

  • Had a simple answer by drinking a water and trying get my brain straight hahahaha

    this is the answer

    const result = roles.filter(
      (dt) => dt[1] === 'member'
    );