Array Methods in JavaScript

 //Array Methods

let num = [1, 2, 3, 34, 4];
let b = num.toString();
console.log(b, typeof b);
let c = num.join("_");
console.log(c, typeof c);
let d = num.join(" and ");
console.log(d, typeof d);
let r = num.pop();  //pop returns the popped element
console.log(num, r);
let r2 = num.push(56);  //push returns the new array length
console.log(num, r2);
let r3 = num.shift();   //shift() Removes first element and returns it
console.log(r3, num);   //Removes an element from the start of the array
let r4 = num.unshift(78); //unshift() Adds element to the beginning.Returns new Array length
console.log(r4, num);


OUTPUT :
1,2,3,34,4 string 1_2_3_34_4 string 1 and 2 and 3 and 34 and 4 string [ 1, 2, 3, 34 ] 4 [ 1, 2, 3, 34, 56 ] 5 1 [ 2, 3, 34, 56 ] 5 [ 78, 2, 3, 34, 56 ]

Comments

Popular posts from this blog

Generators tutorial in Advance JavaScript

Document Object Module DOM querySelector and querySelectorAll tutorial in JavaScript

Find Even and Odd Numbers with Loops tutorial in JavaScript