Để bỏ qua một giá trị cụ thể, hãy sử dụng toán tử logic Not (!) Trong điều kiện if và tìm nạp xem bạn muốn đưa vào.
Ví dụ
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);
}
} Để chạy chương trình trên, bạn cần sử dụng lệnh sau -
node fileName.js.
Đây, tên tệp của tôi là demo179.js.
Đầu ra
Điều này sẽ tạo ra kết quả sau -
PS C:\Users\Amit\javascript-code> node demo179.js The country name is=US The country name is=UK