给出这段JavaScript代码......
var a;
var b = null;
var c = undefined;
var d = 4;
var e = 'five';
var f = a || b || c || d || e;
alert(f); // 4
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释一下这种技术的用途(我最好的猜测是在这个问题的标题中!)?它是如何/为什么它正常工作?
我的理解是变量f将被赋予第一个变量的最近值(从左到右),该变量的值不是null或未定义,但是我没有设法找到关于这种技术的很多参考资料并且有看到它用了很多.
此外,这种技术是否特定于JavaScript?我知道在PHP中做类似的事情会导致产生f一个真正的布尔值,而不是d它自身的值.
我在主/父数组中有多个数组,如下所示:
var array = [[1, 17], [1, 17], [1, 17], [2, 12], [5, 9], [2, 12], [6, 2], [2, 12]];
Run Code Online (Sandbox Code Playgroud)
这是用于简化阅读的数组:
[1, 17]
[1, 17]
[1, 17]
[2, 12]
[5, 9]
[2, 12]
[6, 2]
[2, 12]
[2, 12]
Run Code Online (Sandbox Code Playgroud)
我想选择重复3次或更多次(> 3)的数组并将其分配给变量.所以在这个例子中,var repeatedArrays将是[1, 17]和[2, 12].
所以这应该是最终的结果:
console.log(repeatedArrays);
>>> [[1, 17], [2, 12]]
Run Code Online (Sandbox Code Playgroud)
我在这里发现了类似的东西,但它使用了underscore.js和lodash.
我怎么能用javascript甚至jquery(如果需要)?