Posts

Showing posts from June, 2023

Javascript Array Concat and Join Method

  The JavaScript   Array concat()   Method is used to merge two or more arrays together. This method does not alter the original arrays passed as arguments. but instead return new Array. let newArray1 = oldArray.concat() let newArray2 = oldArray.concat(value0) let newArray3 = oldArray.concat(value0,value1) ....... ....... let newArray = oldArray.concat(value1 , [ value2, [ ...,[ valueN]]]) -------------------------------- Description The  join()  method returns an array as a string. The  join()  method does not change the original array. Any separator can be specified. The default is comma (,). <! DOCTYPE html > < html lang = "en" > < head >   < meta charset = "UTF-8" >   < meta http-equiv = "X-UA-Compatible" content = "IE=edge" >   < meta name = "viewport" content = "width=device-width, initial-scale=1.0" >   < title >Document</ title > </ head > < body >   ...

JavaScript Array Shift() method

  JavaScript  Array Shift() method The   shift()   method removes   the first item   of an array. The  shift()  method changes the original array. The  shift()  method returns the shifted element. <! DOCTYPE html > < html lang = "en" > < head >   < meta charset = "UTF-8" >   < meta http-equiv = "X-UA-Compatible" content = "IE=edge" >   < meta name = "viewport" content = "width=device-width, initial-scale=1.0" >   < title >Document</ title > </ head > < body >   < h1 >JavaScript Array shift()</ h1 >   < script >     const fruits = [ "Banana" , "Orange" , "Apple" , "Mango" ];     const delElem = fruits . shift ();     console . log (delElem);     console . log (fruits);       </ script > </ body > </ html >