Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

javascript - 如何在数组内部的数组中过滤字符串位置?(How to filter a string position inside an array inside an array?)

I'm looking to filter an array by the month and year which found on position 3 of the row where the dates are dd/mm/yyy .

(我正在寻找按月和年过滤的数组,该数组位于日期为dd / mm / yyy的行的位置3上。)

array generated from a google sheets:

(从Google表格生成的数组:)

[[1, 134, DIOGO, 03/ 12 / 2019 , ggggg, 2], [2, 131, ALEISIO, 13/ 11 / 2019 , ggg, 33], [3, 134, DIOGO, 25/ 11 / 2019 , gggg, 2], [4, 134, DIOGO, 15/ 12 / 2019 , tttttt, 2]]

([[1,134,DIOGO 03/12/2019 ,GGGGG,2],[2,131,ALEISIO 13/11/2019 ,GGG,33],[3,134,DIOGO 25/11/2019 , gggg,2],[4,134,DIOGO,15 / 12 / 2019 ,tttttt,2]])

var funcionarioId ="user1"
var month = "11"
var year = "2019";

var dataFiltered = data.filter(function(item){return item[1] === funcionarioId && 
item[3] === month && 
item[3] === year });

The expected results should be:

(预期结果应为:)

[[2, 131, ALEISIO, 13/ 11 / 2019 , ggg, 33], [3, 134, DIOGO, 25/ 11 / 2019 , gggg, 2]]

([[2,131,ALEISIO,13 / 11 / 2019 ,ggg,33],[3,134,DIOGO,25 / 11 / 2019 ,gggg,2]])

  ask by user2916405 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is the code that will get the required data:

(这是将获取所需数据的代码:)

var funcionarioId = '134';
var month = "11"
var year = "2019";

var filteredData = data.filter(function(item) {
var items = item[3].split('/');
return items[1] === month &&
       items[2] === year &&
       item[1] == funcionarioId
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...