-1

How to filter a dataset in javascript?,

my dataset:

 [1, "AGENT001", "John", "bdev1@example.com, "Sales", 1, false, true]
 [2, "AGENT002", "Susan", "bdev2@example.com", "Sales", 1, true, true]

how to filter by the 6th column = true?

Don2
  • 313
  • 3
  • 12
  • 1
    Familiarize yourself with [how to access and process nested objects, arrays or JSON](/q/11922383/4642212) and use the available [`Array`](//developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array#Static_methods) methods (both static and instance). – Sebastian Simon Jul 27 '21 at 03:24
  • [Duplicate](//google.com/search?q=site%3Astackoverflow.com+js+filter+nested+arrays+by+value) of [Filter Array of Array for values inside nested array](/q/55972563/4642212). – Sebastian Simon Jul 27 '21 at 03:25

1 Answers1

2

You can use Array#filter and check whether the item at index 6 is true:

const items = [
  [1, "AGENT001", "John", "bdev1@example.com", "Sales", 1, false, true],
  [2, "AGENT002", "Susan", "bdev2@example.com", "Sales", 1, true, true]
];
const filtered = items.filter(e => e[6]);
console.log(filtered);
Spectric
  • 30,714
  • 6
  • 20
  • 43