0
這是如何在陣列搜索的價值存在:CoffeeScript的:搜索具有特定屬性值的對象
words = ["rattled", "roudy", "rebbles", "ranks"]
alert "Stop wagging me" if "ranks" in words
我在尋找與指定屬性值對象的存在尋找類似的優雅:
words = [
{ id: 1, value: "rattled" },
{ id: 2, value: "roudy" },
{ id: 3, value: "rebbles" },
{ id: 4, value: "ranks" }
]
alert "Stop wagging me" if "ranks" in words.value
但底部的行不起作用。
從這個問題我可以看出,你每創建一個新數組需要檢查存在,如果陣列變大或者在任何實質負載下都非常昂貴。 – matehat 2013-03-12 15:50:25