javascript - Replace an element in an array at a specified index -
i have array:
var left=[323,345,654,123];
how can replace 345
? have tried :
left[2]=456
but didn't work.
(i can use jquery if that's relevant.)
the index in array (in every programming language) starts zero! if want replace second value of array, need index of 1
.
// index: 0 1 2 3 var left = [323, 345, 654, 123]; left[1] = 456;
for further example, array accessible like:
left[0]; // 323 left[1]; // 456 left[2]; // 654 left[3]; // 123
and don't need jquery @ this. is plain, basic javascript.
Comments
Post a Comment