js 过滤两个数组中的相同元素

1. filter 和 find 、some ,includes结合使用

javascript 复制代码
let arr = [1, 2, 3, 4, 5];
let arr2 = [3, 4, 5, 6, 7];

const arr3 = arr.filter((item) => arr2.includes(item));
const arr4 = arr.filter((item) => arr2.find((item2) => item2 === item));
const arr5 = arr.filter((item) => arr2.some((item2) => item2 === item));
console.log(arr3, "arr3");
console.log(arr4, "arr4");
console.log(arr5, "arr5");
/**
 *   [ 3, 4, 5 ] arr3
     [ 3, 4, 5 ] arr4
     [ 3, 4, 5 ] arr5
 */

2.input 上传图片不想要默认 上传样式

javascript 复制代码
<input type="file" id="myFileInput" style="display: none;">
<label for="myFileInput" class="custom-file-upload">自定义文件上传按钮</label>

3. 原生对 地址或者 base64进行编码 的api

encodeComponent() 不会对 ASCII 数字 或者 - _ . ! ~ * ' ( ) 编码 。只对 #¥%@......& ....等编码

防止 服务端解析 这些地址 无法识别

相反

decodeComponent() 解码

|---|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| | js中encodeURIComponent函数的使用,加码解码_玉米妈妈-momoxifei的博客-CSDN博客js中encodeURIComponent函数的使用,加码解码https://blog.csdn.net/yanabcdef/article/details/125988707?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168462975916800226542870%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=168462975916800226542870&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_click~default-2-125988707-null-null.142%5Ev87%5Econtrol_2,239%5Ev2%5Einsert_chatgpt&utm_term=encodeURIComponent&spm=1018.2226.3001.4187 |
| | URL详解以及encodeURI、encodeURIComponent、decodeURI、decodeURIComponent的区别_urlunicodeuri_青颜的天空的博客-CSDN博客 |
| | |

相关推荐
lly2024061 小时前
Bootstrap 警告框
开发语言
2601_949146532 小时前
C语言语音通知接口接入教程:如何使用C语言直接调用语音预警API
c语言·开发语言
曹牧2 小时前
Spring Boot:如何测试Java Controller中的POST请求?
java·开发语言
KYGALYX2 小时前
服务异步通信
开发语言·后端·微服务·ruby
zmzb01032 小时前
C++课后习题训练记录Day98
开发语言·c++
猫头虎3 小时前
如何排查并解决项目启动时报错Error encountered while processing: java.io.IOException: closed 的问题
java·开发语言·jvm·spring boot·python·开源·maven
Moment3 小时前
富文本编辑器在 AI 时代为什么这么受欢迎
前端·javascript·后端
YUJIANYUE3 小时前
PHP纹路验证码
开发语言·php
爱敲代码的小鱼4 小时前
AJAX(异步交互的技术来实现从服务端中获取数据):
前端·javascript·ajax
仟濹4 小时前
【Java基础】多态 | 打卡day2
java·开发语言