1Using a FOR loop, write a function addNumber which adds the argument n to each
2number in the array arr and returns the updated arr:
3const addNumber=(arr, n)=>{
4 let arr1=[];
5 for(let i=0;i<Math.max(arr.length);i++){
6 arr1.push((arr[i]||0)+n)
7 }
8 return arr1;
9}
10console.log(addNumber([4, 5, 6], 7)); // expected log [11, 12, 13]
1let browsers = ['chrome', 'firefox', 'edge'];
2browsers.unshift('safari');
3// add an element at the beginning of array
4console.log(browsers); // ["safari", "chrome", "firefox", "edge"]
5
6let browsers = ['chrome', 'firefox', 'edge'];
7browsers.push('safari');
8// add an element at the end of array
9console.log(browsers); // ["chrome", "firefox", "edge", "safari"]
10
11let browsers = ['chrome', 'firefox', 'edge'];
12browsers.shift();
13// Delete first element of array
14console.log(browsers); // ["firefox", "edge"]
15
16let browsers = ['chrome', 'firefox', 'edge'];
17browsers.pop();
18//delete last elemnent of array
19console.log(browsers); // ["chrome", "firefox"]
20
21// Add and remove anywhere you want
22//Add
23var fruits = ["Banana", "Orange", "Apple", "Mango"];
24function myFunction() {
25 fruits.splice(3, 0, "Lemon", "Kiwi");
26//fruits.splice(Where to add, what to delete, "Lemon", "Kiwi");
27 document.getElementById("demo").innerHTML = fruits;
28}
29//output Banana,Orange,Apple,Lemon,Kiwi,Mango
30
31//Delete
32var fruits = ["Banana", "Orange", "Apple", "Mango"];
33function myFunction() {
34 fruits.splice(2, 1);
35// fruits.splice(where to delete, how many);
36 document.getElementById("demo").innerHTML = fruits;
37}// output: Banana,Orange,Mango