在 JavaScript 中通过忽略特定值来获取值?
javascriptweb developmentobject oriented programming更新于 2025/11/18 5:32:17
要忽略特定值,请在 if 条件中使用逻辑 Not (!) 运算符并获取要包含的监视。
示例
var customerDetails=[
{
customerName:"John",
customerAge:28,
customerCountryName:"US"
},
{
customerName:"David",
customerAge:25,
customerCountryName:"AUS"
},
{
customerName:"Mike",
customerAge:32,
customerCountryName:"UK"
}
]
for(var i=0;i<customerDetails.length;i++){
if(customerDetails[i].customerCountryName!="AUS"){
console.log("The country name
is="+customerDetails[i].customerCountryName);
}
}
要运行上述程序,您需要使用以下命令 −
node fileName.js.
这里,文件名是 demo179.js。
输出
这将产生以下输出 −
PS C:\Users\Amit\javascript-code> node demo179.js The country name is=US The country name is=UK
相关文章
有用资源
javascript 参考教程 - 该教程包含有关 javascript 的更多信息:https://www.cainiaomax.com/javascript/

