var
names = [
“Paul”, // Index number 0
“Peter”, // Index number 1
“Carl” // Index number 2
];
var secondName = names[1]; // variable will be set to “Peter”
Analysing the example, we can see that we have created an array with the values ‘John’, ‘Peter’ and ‘Carl’. Then we assign the variable secondName to the second value in the array ‘names’.
At any point after the creation of an array, we can manually set the value of a position in the array by simply passing the data to the array’s position, like so: