filtering 2d arrays using javascript

前端 未结 5 1936
眼角桃花
眼角桃花 2021-01-28 06:23

I have a 2D array where I need to filter the rows having date field (3d column)

var data = [
[\'1\',\'a\',\'12-12-2019\',\'A\'],
[\'2\',\'b\',\'\',\'A\'],
[\'3\'         


        
5条回答
  •  心在旅途
    2021-01-28 07:14

    It seems pretty straightforward to just use Array.filter, checking to see if the date field is empty or not.

    var data = [
    ['1','a','12-12-2019','A'],
    ['2','b','','A'],
    ['3','c','12-1-2019','A'],
    ['4','d','','A'],
    ];
    
    var filtered = data.filter(e => e[2]);
    
    console.log(filtered);

提交回复
热议问题