如果匹配,我試圖只返回鍵值。const codes = { key1: 'dafault', key2: 'dog112', key3: 'catStick',};const match = 'dog'const result = Object.entries(codes).filter(([, v]) => { console.log('v = ', v); return v.includes(match);});console.log('result = ', result);// Array(2) ["key2", "dog112"]我只需要返回鍵值。我如何提取鍵值或者是否有更簡單的方法來在匹配時返回鍵。
從 Object.entries 中提取值
三國紛爭
2021-12-02 19:26:59