有人可以向我解释这个JS代码吗?

有人可以向我解释这个JS代码吗?

问题描述:

var a1 = [[0,1],[0,1],[1,1]],
    a2 = [[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]],
   res = a2.map((s,i) => s.map((n,j) => a1[i][j] !== void 0 ? a1[i][j] : n));



代码应该将a1覆盖到a2上,但它究竟是如何做到的?

变量s,i,j和n有哪些?

代码取自这个问题:如何在JavaScript中将2D数组放在另一个上面 - Quora [ ^ ]



我尝试了什么:



我已经尝试将代码放入 jsfiddle 它发现了一些错误,但似乎有效。


The code is supposed to overlay a1 onto a2, but how exactly does it do this?
What are the variables s, i, j, and n?
Code taken from answer to this question: How to impose a 2D array on top of another in JavaScript - Quora[^]

What I have tried:

I have tried putting the code in to jsfiddle where it finds some errors but it seems to work.

请看这里: JavaScript的Lambda和Arrow函数| Vinta Software [ ^ ]


要添加到解决方案1,此
To add to solution 1, this
res = a2.map((s,i) => s.map((n,j) => a1[i][j] !== void 0 ? a1[i][j] : n));

与此相同:

res=a2.map(function(s,i){

	return s.map(function(n,j){

		if (a1[i][j] !== void 0){
			return a1[i][j];
		} else {
			return n;
		}
	
    })

})

。了解 JavaScript数组映射()方法 [ ^ ]