JavaScript/array/find:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
创建页面,内容为“== 引言 == == other == find 方法会更改引用 {{leftrightflex|<syntaxhighlight lang="javascript"> const source = [1,2,3]; const target = source.find(_ => _ ===…”
 
Kangkk​(留言 | 贡献)
第2行: 第2行:
== other ==
== other ==
find 方法会更改引用
find 方法会更改引用
{{leftrightflex|<syntaxhighlight lang="javascript">
{{leftrightflex|<syntaxhighlight lang="javascript">const source = [1,2,3];
const source = [1,2,3];
const target = source.find(_ => _ === 1);
const target = source.find(_ => _ === 1);
source[0] = 4;
source[0] = 4;
console.log(source);
console.log(source);
console.log(target);
console.log(target);</syntaxhighlight>|{{consoleout|<pre>[4, 2, 3]
</syntaxhighlight>|{{consoleout|<pre>
1</pre>}}}}
[4, 2, 3]
1
</pre>}}}}