Using a FOR loop, write a function addNumber which adds the argument n to each
number in the array arr and returns the updated arr:
const addNumber=(arr, n)=>{
let arr1=[];
for(let i=0;i<Math.max(arr.length);i++){
arr1.push((arr[i]||0)+n)
}
return arr1;
}
console.log(addNumber([4, 5, 6], 7)); // expected log [11, 12, 13]
let newArray = oldArray.map(funcToEachElem);
people[0] = "Georgie";
//Given array
const ar=[1, 2, 3, 4, 5];
//Taking number from user to alter the array
var p=parseInt(prompt());
//Creating function body
const addNumber=(arr, n)=>{
let arr1=[];
for(let i=0;i<Math.max(arr.length);i++){
arr1.push((arr[i]||0)+n)
}
return arr1;
}
//printing old array
document.write("Old array: "+ar);
//printing new array by calling the function and passing the parametter
document.write("new array: "+addNumber(ar, p));
let dailyActivities = [ 'eat', 'sleep'];
// this will add the new element 'exercise' at the 2 index
dailyActivities[2] = 'exercise';
console.log(dailyActivities); // ['eat', 'sleep', 'exercise']