You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
918 B
JavaScript

console.log('hello world');
let fruits = ['apple','orange','kiwi','dragonfruit'];
console.log('current array');
console.log(fruits);
let fruitfresh = fruits.push('mango');
console.log(fruitfresh);
console.log('Mutate array from push method');
console.log(fruits);
fruits.push('guava');
console.log(fruits);
fruits.push('guava', 'durian');
console.log(fruits);
function addfruit(fruit){
fruits.push(fruit);
}
// envoke outside the function//
addfruit('apple')
console.log(fruits);
// unshifts
//syntax:
//arrayName.unshift('elementa');
//arrayName.unshift('elementa', 'elementb');
fruits.unshift('lime', 'banana')
console.log(fruits);
function addfruit(fruit){
fruits.unshift(fruit);
}
// envoke outside the function//
addfruit('calamansi')
console.log(fruits);
// shift
//syntax: arrayName.shift()
let fruitsnow = fruits.shift('grapes', 'strawberry')
console.log(fruitsnow);
console.log(fruits);