freeCodeCamp/guide/chinese/certifications/javascript-algorithms-and-d.../basic-javascript/modify-array-data-with-indexes/index.md

422 B

title localeTitle
Modify Array Data With Indexes 使用索引修改数组数据

使用索引修改数组数据

访问数组的位置,并更改它,如下所示:

var arr = [1, 2, 3, 4, 5]; 
 
 arr[0] = 6; // Now, the array is [6, 2, 3, 4, 5] 
 arr[4] = 10 // Now, the array is [6, 2, 3, 4, 10] 

这里重要的概念是数组是可变的 。这意味着它们可以轻松更改。