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博客 |
| | |

相关推荐
柯南二号11 分钟前
【Java后端】MyBatis-Plus 原理解析
java·开发语言·mybatis
我是哈哈hh31 分钟前
【Node.js】ECMAScript标准 以及 npm安装
开发语言·前端·javascript·node.js
张元清1 小时前
电商 Feeds 流缓存策略:Temu vs 拼多多的技术选择
前端·javascript·面试
pepedd8641 小时前
浅谈js拷贝问题-解决拷贝数据难题
前端·javascript·trae
@大迁世界1 小时前
useCallback 的陷阱:当 React Hooks 反而拖了后腿
前端·javascript·react.js·前端框架·ecmascript
小高0071 小时前
📌React 路由超详解(2025 版):从 0 到 1 再到 100,一篇彻底吃透
前端·javascript·react.js
summer7771 小时前
GIS三维可视化-Cesium
前端·javascript·数据可视化
Sammyyyyy2 小时前
2025年,Javascript后端应该用 Bun、Node.js 还是 Deno?
开发语言·javascript·node.js
小高0073 小时前
面试官:npm run build 到底干了什么?从 package.json 到 dist 的 7 步拆解
前端·javascript·vue.js
William一直在路上3 小时前
Python数据类型转换详解:从基础到实践
开发语言·python