1

前端问题 为什么我的 fliter 能改变原数组?网上全部都是 filter 不改变原数组....

 2 years ago
source link: https://www.v2ex.com/t/855112
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  问与答

前端问题 为什么我的 fliter 能改变原数组?网上全部都是 filter 不改变原数组....

  particlec · 22 小时 3 分钟前 · 1732 次点击

const [selectProductKey, setSelectProductKey] = useState([]);

// 搜索框 key 匹配数组 productKey const matchProductKey = key => { let temporaryArr = [...productKeyArr]; temporaryArr.filter(obj => obj.slice(key) !== -1); setSelectProductKey(temporaryArr); };

onSearch={e => {matchProductKey(e);}}

// 这里的 selectProductKey 数组确实被筛选了 {selectProductKey.map(key => (<Select.Option value={key}>{key}</Select.Option>))}


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK