TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: In JavaScript, changing the value of an array item not advised?

2 点作者 mcdoh将近 15 年前
I'm reading through jQuery Fundamentals (http://www.rebeccamurphey.com/jqfundamentals/#javascript-basics.examples.change-array-value) and this tip in the JavaScript chapter surprised me: <i>While it's possible to change the value of an array item as shown in Example 2.28, “Changing the value of an array item”, it's generally not advised.</i><p>I wouldn't think just changing the value of an array element could cause a problem. Is this truly inadvisable or was this written in error?

1 comment

byoung2将近 15 年前
It shouldn't be a problem with strings and numerics in arrays (the array contains copies of the values), but with arrays of functions/objects, the elements of the array are not copies, but the actual objects themselves. So if you change an object in the array, the object itself changes (and vice versa).
评论 #1478927 未加载