在 JavaScript 中透過忽略一個特定值來獲取值?
要忽略特定值,請在 if 條件中使用邏輯非 (!) 運算子,並獲取想要輸入的監視。
示例
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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP