Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript-根据条件查找矩阵中的第一个索引_Javascript_Search_Indexof - Fatal编程技术网

Javascript-根据条件查找矩阵中的第一个索引

Javascript-根据条件查找矩阵中的第一个索引,javascript,search,indexof,Javascript,Search,Indexof,具有以下矩阵阵列: [ [0,0,1,1,0,3], [1,0,0,1,2,5], [0,0,1,2,4,9] ] 我想找到索引3,它是所有值都大于0 1,1,2的第一列 搜索此索引的有效技术是什么 您可以将每种方法与findIndex方法结合使用 var arr = [ [0,0,1,1,0,3], [1,0,0,1,2,5], [0,0,1,2,4,9] ] var res = arr.map((a) => a.filter((b) => b > 0)) or var

具有以下矩阵阵列:

[
[0,0,1,1,0,3],
[1,0,0,1,2,5],
[0,0,1,2,4,9]
]
我想找到索引3,它是所有值都大于0 1,1,2的第一列

搜索此索引的有效技术是什么

您可以将每种方法与findIndex方法结合使用

var arr = [
[0,0,1,1,0,3],
[1,0,0,1,2,5],
[0,0,1,2,4,9]
]

var res = arr.map((a) => a.filter((b) => b > 0))
or
var res = arr[0].filter((b) => b > 0)
console.log(res)
findIndex方法返回数组中满足所提供回调测试函数的第一个元素的索引

each方法测试数组中的所有元素是否通过回调函数提供的测试

设矩阵=[[0,0,1,1,0,3],[1,0,0,1,2,5],[0,0,1,2,4,9]] 设索引=矩阵[0]。findIndexfunctioncell,i{ 返回矩阵。everyfunctionrow{ 返回行[i]>0;//或返回行[i]; }; };
console.logindex 您可以映射所有truthy值,并使用Boolean作为回调查找索引。 var数组=[[0,0,1,1,0,3],[1,0,0,1,2,5],[0,0,1,2,4,9], 索引=数组 .reducea,b=>a.mapc,i=>b[i]&&c .findIndexBoolean;
console.logindex;请回顾一下,特别是你被困在哪里?你的研究结果是什么?你解决问题的尝试是什么样的?你对此有什么具体问题?现在,这读起来像是请为我做这件事,这不是为什么。它对你有用,@Shlomi?是的,谢谢,很有魅力