简体   繁体   中英

How to find exact string

I have an array:

and I trying to find the exactly string value with this

It works fine even if you are looking for "b" or "bt" but I would like to get result only when i'm looking for "btc" (exactly string value)

when I look for "b" or "bt" I want to get no result

 let coinsArray = [{ symbol: "btc" }] let newStatus = coinsArray.filter(coin => coin.symbol.includes($(".InpSearchCoin").val())) console.log(newStatus)
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="text" class="InpSearchCoin" value="btc" />

Don't use includes

 let coinsArray = [{ symbol: "btc" }] $(".InpSearchCoin").on("input", function() { let symbol = coinsArray.filter(({symbol}) => symbol === this.value.toLowerCase()) console.log(symbol) })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="text" class="InpSearchCoin" value="" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM