|
| 1 | +//Array |
| 2 | +const arr = [0, 1, 2, 3, 4]; |
| 3 | +//console.log(arr); |
| 4 | + |
| 5 | +const fruit = ["banana", "orange", "Apple", "grapes"]; |
| 6 | +//console.log(fruit); |
| 7 | + |
| 8 | +const mixFruit = ["Apple", "grapes", 2, true, undefined, JSON]; |
| 9 | +//console.log(mixFruit); |
| 10 | + |
| 11 | +const newArray = new Array(0, 1, 2, 3); |
| 12 | +//console.log(newArray); |
| 13 | +//console.log(newArray[1]); //1 |
| 14 | + |
| 15 | +// Methods |
| 16 | +newArray.push(4); |
| 17 | +newArray.push(5); |
| 18 | +//console.log(newArray); |
| 19 | +newArray.pop(); |
| 20 | +//console.log(newArray); |
| 21 | + |
| 22 | +newArray.unshift(-1); // add -1 into start |
| 23 | +//console.log(newArray); |
| 24 | + |
| 25 | +newArray.shift(); //remove first element |
| 26 | +//console.log(newArray); |
| 27 | + |
| 28 | +//console.log(newArray.length); //5 |
| 29 | + |
| 30 | +console.log("A", newArray); |
| 31 | +console.log(newArray.slice(1, 3)); // it will give me values from 1 to 2 index |
| 32 | +console.log(newArray); // return full array |
| 33 | + |
| 34 | +console.log("B", newArray); |
| 35 | +console.log(newArray.splice(1, 3)); // it will give me values from 1 to 3 index |
| 36 | +console.log("c", newArray); //cut the orignal array and return remaing values of array |
0 commit comments