Posts

Showing posts from September, 2022

JS: Operations with object

//* Operations with Object *// let info = {     firstName: 'Virat',     lastName: 'Kohli' } //1) retrieve property & value from boject //dot notation console.log(info.firstName) console.log(info.lastName) //bracket notation console.log(info['firstName']) console.log(info['lastName']) //2) add property to object //dot notation info.age = 32 console.log(info) //bracket notation info['city'] = 'Delhi' console.log(info) //3) update property of object //dot notation info.firstName = 'Vrendra' console.log(info) //bracket notation info['lastName'] = 'Sehwag' console.log(info) //4) delete property of object //dot notation delete info.city console.log(info) //bracket notation delete info['age'] console.log(info) //Example 2 with dot notation info2 = {     CarName: 'Scorpio',     Color: 'White' } // retrive console.log(info2.CarName) console.log(info2.Color) // add info2.Model = 2020 console.log(i...

JS: String property & methods

//* String property & methods *// //A) String property 1) length : returns the length of string //B) String methods 1)   slice() 2)   replace() 3)   toUpperCase() 4)   toLowerCase() 5)   concat() : joins two different strings 6)   trim() : removes whitespace from both sides of a string 7)   trimStart() : removes whitespace only from the start of a string 8)   trimEnd() : removes whitespace only from the end of a string 9)   charAt() : method returns the character at a specified index (position) in a string 10) startsWith() : Checks whether a string begins with specified characters 11) endsWith() : Checks whether a string ends with specified characters 12) includes() : Returns if a string contains a specified value 13) indexOf() : Returns the index (position) of the first occurrence of a value in a string 14) repeat() : returns a new string with a number o...

JS: Operations with Array: retrieve, add, update, delete

//* Operations with Array *// 16-sep-2022 //1) retrieve elements from array //                              0            1             2 let vegetables = ['tomato', 'potato', 'spinach'] console.log(vegetables) console.log(vegetables[0]) console.log(vegetables.at(0)) console.log(vegetables.at(2)) //2) add element to array let f1 = vegetables.push('brinjal') // adds element at end console.log(f1) // returns new length of array console.log(vegetables) // returns updated array // updated array --> ['tomato', 'potato', 'spinach', 'brinjal] let f2 = vegetables.unshift('cabbage') // adds element at start console.log(f2) // returns new length of array console.log(vegetables) // returns updated array // updated array --> ['cabbage', tomato', 'potato', 'spinach', 'brinjal] //3) update element of array //              ...

JS : Array methods

//* methods of array *// // 1) push(): adds element at end of array // 2) unshift(): adds element at start of array // 3) pop(): removes last element of array // 4) shift(): removes first element of array // 5) includes(): checks if an element is present in array and return boolean value // 6) filter(): filters element of array by given condition  // 7) map(): we can use this method instead of loop  // 8) reduce(): we can use this method instead of loop // 9) forEach(): do modification for each element //10) find(): finds the element by given condition & returns that element //11) findIndex(): finds the index of element by given condition & returns index of that element  //12) some(): find element by given condition & return boolean value //13) every(): find element by given condition & return boolean value //14) slice(): returns elements between given indexes //15) reverse(): reverse the elements //16) flat(): combines sub-arrays of a array and returns a ...