You can directly change values in an array.
const arr = [1, 2 , 3, 4, 5];
arr[0] = arr[0] +1; //this will add 1 to the value in index 0 (1 + 1)
console.log(arr); //this would output [2, 2, 3, 4, 5]
Array methods take functions to do more complex logic.
const arr = [1, 2 , 3, 4, 5];
const addOne = arr.map(num => num + 1); //this adds 1 to every value within arr
console.log(addOne); //this logs [2, 3, 4, 5, 6]
These array methods make it easy to use logic on the values in an array. You could create your own function to do this but it would be a little more cumbersome.
This is a how you could make a new array with some logic to change each value but without using the Array.map() method:
const arr = [1, 2 , 3, 4, 5];
const addOne = () =>{
const copyArr = arr.slice(); //make a copy of the array (you can skip this step if you want to directly change the original array)
for( let i = 0; i < copyArr.length; i++ ){ //loop over every index of the array
copyArr[i] = copyArr[i] + 1; //add one to each index
}
return copyArr; //return the new array
};
const newArr = addOne(arr); //call the function on the original array
console.log(newArr); // this will log [2, 3, 4, 5, 6]
This will make a lot more sense when you get further into this course.