includes
发表于|更新于
|浏览量:
一个人能在鼠疫和生活的赌博中所赢得的全部东西,就是知识和记忆。——《鼠疫》
我们除了使用indexOf判断字符串/数组是否包含某字符/元素还可以使用includes
区别在于数组判断中indexOf对NaN值处理会错误,而includes不会,例如:

这里显示-1说明没有匹配到
而使用includes:

可以看到成功匹配
字符串也可以使用includes

非常的方便
我们可以用prototype获取原型对象然后再调用
1 | Array.prototype.includes.call([1,2,3,4],1) |
还是蛮方便的
相关推荐
2024-02-13
js实现出拳蓄力发射效果
贤妻和健康是一个男子最宝贵的财富。——斯珀吉翁 分享一个蓄力出拳的特效 这个效果放到了codepen里 123456789101112131415161718<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>蓄力发射拳头</title><link rel="stylesheet" href="style.css"></head><body><div id="rocket-container"> <div id="rocket">✊</div>...
2022-09-01
blob和base64互转
交易场上的朋友胜过柜子里的钱款——托·富勒 blob转base64 1234567891011121314151617// blob转base64async function blobToBase64(blob) { let buffer = await blob.arrayBuffer() let bytes = new Uint8Array(buffer); console.log(bytes) // do anything with the byte array here let binary = '' var len = bytes.byteLength; for (var i = 0; i < len; i++) { binary += String.fromCharCode(bytes[i]); } base64 = 'data:image/webp;base64,' + window.btoa(binary) co...
2020-10-21
页面点击随机字符
不要让昨天占用今天的时间。 ——美洲 应群友的要求分享给大家~ 123456789101112131415161718192021222324252627282930313233343536//随机字$(function () { var a_idx = 0, b_idx = 0; c_idx = 0; jQuery(document).ready(function ($) { $("body").click(function (e) { var a = new Array("Daphne", "Ficus", "Iris", "Maackia", "Lythrum", "Myrica", "Sabia", "Flos", "あなたのことが好きです", "嬉しい", "頑張って!"...
2024-06-08
vuesax一些组件找不到踩坑
祸生于欲得,福生与自禁。——刘向 今天发现vuesax有一些组件用不了了,弄了半天,没办法去github上看了看 发现这个人也是相同问题 https://github.com/lusaxweb/vuesax-next/issues/208 然后翻issue看到一个不继续开发的issue https://github.com/lusaxweb/vuesax-next/issues/297 这里提到 A fork of Vuesax V4 has been created that works with Vue 3 and Nuxt 3. Additionally, the fork includes new components that are not present in V4. I suggest using and contributing to fork instead. Vuesax V4 的一个分支已经创建,可与 Vue 3 和 Nuxt 3 配合使用。此外,该分支还包含 V4 中不存在的新组件。我建议改为使用 fork 并为其做出贡献。 这里跳转过来是一个v...
2025-10-15
jekyll-theme-chirpy
窥天地之奥而达造化之极——李时珍 https://github.com/cotes2020/jekyll-theme-chirpy Chirpy:技术写作的极致优雅——Jekyll 最受欢迎的极简响应式主题如果你是技术极客、程序员、运维、独立开发者,或是任何热爱写作和分享的人,相信你一定会关注“博客体验”这件小事。你想要页面清爽、内容聚焦、功能强大、移动端友好、上手成本低?那么,Chirpy 绝对值得你深入体验! 一、项目简介 项目地址:cotes2020/jekyll-theme-chirpy 演示站点:https://chirpy.cotes.page 一句话描述:A minimal, responsive, and feature-rich Jekyll theme for technical writing. 主语言:HTML(基于 Jekyll,支持 RubyGems) Star:9310+ Fork:7041+ 开源协议:MIT 标签:jekyll jekyll-theme responsive-web-design html5 bootstrap p...
2025-05-20
Minecraft颜色选择转换
天行健,君子以自强不息。——《周易·乾·象》 https://codepen.io/0biwan/pen/ggVemP html 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071<div class="container"> <div class="tools"> <div class="colors"> <button data-color="0" class="bg-1">&0</button> <button data-color="1" class="bg-2">&1</button> &...
