// CLASS TOPICS : FEW METHOD OF Array DATA TYPES
// reverse
// list = ["a","b","c","d"].reverse();
// console.log(list);
// it will reverse the array whether it is array of string, number whatever
// Pop
// list = [1,2,3,4];
// list.pop();
// console.log(list);
// it will remove the last element from array
// why we are writing .pop in next line?
// because pop will remove last element from orignal array it is going to return only the elemet it is removing not a new array.
// if we write list = [1,2,3,4].pop() then as i said it will return last element that is 4
// Slice
// list = [1,2,3,4,5].slice(0,4)
// console.log(list);
// same as in string
// To string
// list = [1,2,3,4].toString()
// console.log(list,typeof(list));
// convert array to a string
// Concat
// list = [1,2,3,4,5].concat(["a","B","c"],["d","e"])
// console.log(list);
// merge two or more arrays
// CLASS TOPICS : SPREAD OPERATORS // we cannot sum two array like // array1 = [1,2,3,4,5] // array2 = [6,7,8] // array3 = array1 + array2 // console.log(typeof(array3)); // we will get type string instead of a new array // using spread opearators // array1 = [1,2,3,4,5] // array2 = [6,7,8] // array3 = [...array1,...array2] // console.log(array3) // we can sum up two arrays [...] then array name like array1 and then again ...array2 // to sum up and get a new array with elements of both arrays // using spread operator on object // obj1 = {name:"shagun",age:23} // obj2 = {gender:"male",name:"xyz"} // obj3 = {...obj1,...obj2} // console.log(obj3) // here the only diff is that those properties which are same will get //updated because we cannot have two key
Comments
Post a Comment