我目前一個學生學習的Javascript和下面的代碼在我的工作上來:!== -1的意義是什麼?
var currentInventory = [
{
name: 'Brunello Cucinelli',
shoes: [
{name: 'tasselled black low-top lace-up', price: 1000},
{name: 'tasselled green low-top lace-up', price: 1100},
{name: 'plain beige suede moccasin', price: 950},
{name: 'plain olive suede moccasin', price: 1050}
]
},
{
name: 'Gucci',
shoes: [
{name: 'red leather laced sneakers', price: 800},
{name: 'black leather laced sneakers', price: 900}
]
}
];
function filterBlackShoes(shoeList) {
return shoeList.filter(function(shoe){
return shoe.name.indexOf('black') !== -1;
})
}
function renderBlackShoesForDesigner(designer, shoeList) {
shoeList = filterBlackShoes(shoeList);
return shoeList.map(function(shoe){
return [designer, shoe.name, shoe.price].join(', ')
})
}
function renderFilteredGoodsStringForDesigner(designerObject) {
return renderBlackShoesForDesigner(designerObject.name,
designerObject.shoes).join('\n');
}
function renderInventory(inventory) {
return inventory.map(function(designerObject) {
return renderFilteredGoodsStringForDesigner(designerObject);
}).join('\n');
}
所以我理解的代碼做什麼,它過濾了黑色的鞋子,並返回信息。我瞭解代碼如何工作的所有方面,除了!== -1所做的。我會去我的老師,但他們目前處於離線狀態。有人能解釋這對我的意義嗎?
這就是一個比較聲明 – ZeekHuge
我知道,但它與-1 –
比較的意義是什麼它根據[*嚴格相等比較算法*](http:/ *)測試值不是'-1'/ECMA-國際。org/ecma-262/8.0 /#sec-strict-equality-comparison)(即它必須是數值-1)。如果未找到匹配項,[* indexOf *方法](http://ecma-international.org/ecma-262/8.0/#sec-string.prototype.indexof)將返回-1。 – RobG