在javascript中具有多个值的isNaN()函数
可以在javascript中检查isNaN函数中的多个值吗? 像这样,在javascript中具有多个值的isNaN()函数,javascript,Javascript,可以在javascript中检查isNaN函数中的多个值吗? 像这样, if(isNaN(tesvalue1,testvalue2,testvalue3)) { //alert( ); } 尝试此函数以测试某些值是否为NaN: function testSomeNaN() { return Array.prototype.slice.call(arguments).some(isNaN); } function testEveryNaN() { return
if(isNaN(tesvalue1,testvalue2,testvalue3)) {
//alert( );
}
尝试此函数以测试某些值是否为NaN:
function testSomeNaN() {
return Array.prototype.slice.call(arguments).some(isNaN);
}
function testEveryNaN() {
return Array.prototype.slice.call(arguments).every(isNaN);
}
更新1
要测试是否所有值均为NaN,请执行以下操作:
function testSomeNaN() {
return Array.prototype.slice.call(arguments).some(isNaN);
}
function testEveryNaN() {
return Array.prototype.slice.call(arguments).every(isNaN);
}
更新2
如果您想知道arguments数组中的哪些项是数字:
function filterNonNaN() {
return Array.prototype.slice.call(arguments)
.filter(function(x){return !isNaN(x);});
}
更新3
如果阵列中有所有数据,请使用:
var arr = [1,2,NaN,3];
if(arr.some(isNaN)) {...} // some elements are NaN
// or
if([1,2,NaN,3].some(isNan)) {...}
if(arr.every(isNaN)) {...}// all elements are NaN
var arr2 = arr.filter(function(x){return !isNaN(x)}); // non-NaN elements
函数testSomeNaN(){
返回Array.prototype.slice.call(参数).some(isNaN);
}
函数testerynan(){
返回Array.prototype.slice.call(参数).every(isNaN);
}
函数filterOnNan(){
returnarray.prototype.slice.call(arguments).filter(函数(x){return!isNaN(x);});
}
document.getElementById(“res11”).textContent=testSomeNaN(1,2,NaN,4);
document.getElementById(“res12”).textContent=testSomeNaN(1,2,3,4);
document.getElementById(“res13”).textContent=testSomeNaN(NaN,NaN);
document.getElementById(“res21”).textContent=testEveryNaN(1,2,NaN,4);
document.getElementById(“res22”).textContent=TesteryNan(1,2,3,4);
document.getElementById(“res23”).textContent=testEveryNaN(NaN,NaN);
document.getElementById(“res31”).textContent=filterNonNaN(1,2,NaN,4)代码>
一些NaN:
1,2,NaN,4:
1,2,3,4:
楠,楠:
每年:
1,2,NaN,4:
1,2,3,4:
楠,楠:
过滤非NaN:
1,2,NaN,4:
尝试此函数以测试某些值是否为NaN:
function testSomeNaN() {
return Array.prototype.slice.call(arguments).some(isNaN);
}
function testEveryNaN() {
return Array.prototype.slice.call(arguments).every(isNaN);
}
更新1
要测试是否所有值均为NaN,请执行以下操作:
function testSomeNaN() {
return Array.prototype.slice.call(arguments).some(isNaN);
}
function testEveryNaN() {
return Array.prototype.slice.call(arguments).every(isNaN);
}
更新2
如果您想知道arguments数组中的哪些项是数字:
function filterNonNaN() {
return Array.prototype.slice.call(arguments)
.filter(function(x){return !isNaN(x);});
}
更新3
如果阵列中有所有数据,请使用:
var arr = [1,2,NaN,3];
if(arr.some(isNaN)) {...} // some elements are NaN
// or
if([1,2,NaN,3].some(isNan)) {...}
if(arr.every(isNaN)) {...}// all elements are NaN
var arr2 = arr.filter(function(x){return !isNaN(x)}); // non-NaN elements
函数testSomeNaN(){
返回Array.prototype.slice.call(参数).some(isNaN);
}
函数testerynan(){
返回Array.prototype.slice.call(参数).every(isNaN);
}
函数filterOnNan(){
returnarray.prototype.slice.call(arguments).filter(函数(x){return!isNaN(x);});
}
document.getElementById(“res11”).textContent=testSomeNaN(1,2,NaN,4);
document.getElementById(“res12”).textContent=testSomeNaN(1,2,3,4);
document.getElementById(“res13”).textContent=testSomeNaN(NaN,NaN);
document.getElementById(“res21”).textContent=testEveryNaN(1,2,NaN,4);
document.getElementById(“res22”).textContent=TesteryNan(1,2,3,4);
document.getElementById(“res23”).textContent=testEveryNaN(NaN,NaN);
document.getElementById(“res31”).textContent=filterNonNaN(1,2,NaN,4)代码>
一些NaN:
1,2,NaN,4:
1,2,3,4:
楠,楠:
每年:
1,2,NaN,4:
1,2,3,4:
楠,楠:
过滤非NaN:
1,2,NaN,4:
我想你是在以下时间来的:
如果要测试所有值是否为NaN,请使用&&运算符:
if(isNaN(tesvalue1) && isNaN(testvalue2) && isNaN(testvalue3)) {
//alert( );
}
if(isNaN(tesvalue1) || isNaN(testvalue2) || isNaN(testvalue3)) {
//alert( );
}
如果要测试任何值是否为NaN,请使用| |运算符:
if(isNaN(tesvalue1) && isNaN(testvalue2) && isNaN(testvalue3)) {
//alert( );
}
if(isNaN(tesvalue1) || isNaN(testvalue2) || isNaN(testvalue3)) {
//alert( );
}
或者,如果要组合(添加)所有值并测试其是否为NaN:
if(isNaN(tesvalue1+testvalue2+testvalue3)) {
//alert( );
}
我想你是在:
如果要测试所有值是否为NaN,请使用&&运算符:
if(isNaN(tesvalue1) && isNaN(testvalue2) && isNaN(testvalue3)) {
//alert( );
}
if(isNaN(tesvalue1) || isNaN(testvalue2) || isNaN(testvalue3)) {
//alert( );
}
如果要测试任何值是否为NaN,请使用| |运算符:
if(isNaN(tesvalue1) && isNaN(testvalue2) && isNaN(testvalue3)) {
//alert( );
}
if(isNaN(tesvalue1) || isNaN(testvalue2) || isNaN(testvalue3)) {
//alert( );
}
或者,如果要组合(添加)所有值并测试其是否为NaN:
if(isNaN(tesvalue1+testvalue2+testvalue3)) {
//alert( );
}
你期望结果是什么<代码>真/假
或是NaN
的值?不。说真的,要检查这一点有多难?顺便说一句,谷歌是你的朋友。搜索isNaN
时的第一个结果:我不清楚你现在在问什么,因为预期的行为没有定义,现有的两个答案已经实现了相反的行为。你期望结果是什么<代码>真/假
或是NaN
的值?不。说真的,要检查这一点有多难?顺便说一句,谷歌是你的朋友。搜索isNaN
时的第一个结果:我投票不清楚你现在在问什么,因为预期的行为没有定义,而且两个现有的答案已经实现了相反的行为。完全不清楚这是否是OP的预期行为。切片参数
。我认为过滤器()
更合适,因为some()。some()函数比filter()2更快。如果您需要测试所有值,请使用each(isNaN)而不是some(isNaN)。OP的目的是知道参数数组中的哪些项是数字,因此filter()
更合适,因为完全不清楚这是否是OP的预期行为。切片参数
。我认为filter()
更合适,因为some()。some()函数比filter()2更快。如果您需要测试所有值,请使用each(isNaN)而不是some(isNaN)。OP的目的是了解参数数组中的哪些项是数字,因此filter()
更合适。谢谢您的回复,它正在工作:)谢谢您的回复,它正在工作:)