在 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

更新於:12-Sep-2020

328 瀏覽

開啟你的事業

完成課程認證

開始
廣告
© . All rights reserved.