Posts

Delete the april month from an array using Splice Method and indexOf method

  <! DOCTYPE html > < html lang = "en" > < head >   < meta charset = "UTF-8" >   < meta name = "viewport" content = "width=device-width, initial-scale=1.0" >   < title >Splice method </ title > </ head > < body >   < h1 >Delete the april month from an array using Splice Method and indexOf method</ h1 >   < script >       const arrMonths = [ 'jan' , 'feb' , 'march' , 'april' , 'may' ];     // arrMonths.splice(3, 1);     console . log (arrMonths);     const deleteApril = "march" ;     const delIndex = arrMonths . indexOf (deleteApril);     console . log ( `Index of ${ deleteApril } = ${ delIndex }` );     if (delIndex != -1 ){       arrMonths . splice (delIndex, 1 );       console . log (arrMonths);     } else {       console . log ( "Elemen not fou...

JavaScript Splice() method

  Syntax array .splice( index ,  howmany ,  item1 , .....,  itemX ) Parameters Parameter Description index Required. The position to add/remove items. Negative value defines the position from the end of the array. howmany Optional. Number of items to be removed. item1 , ...,  itemX Optional. New elements(s) to be added. <! DOCTYPE html > < html lang = "en" > < head >   < meta charset = "UTF-8" >   < meta name = "viewport" content = "width=device-width, initial-scale=1.0" >   < title >Splice method </ title > </ head > < body >     < h1 >Javascript Splice Method</ h1 >   < script >       // Aditya = Aditya Sharma       // array.splice(index, howmany deletes, item1, ....., itemX)       const myArr = [ "Seema" , "Aditya" , "Reema" , "Vandana" ];       //  myArr.splice(1,0, "Aditya Sharma"); ...

JavaScript Slice() method

  JavaScript Array slice() array .slice( start ,  end ) Description The  slice()  method returns selected elements in an array, as a new array. The  slice()  method selects from a given  start , up to a (not inclusive) given  end . The  slice()  method does not change the original array.   const fruits = [ "Banana" , "Orange" , "Lemon" , "Apple" , "Mango" ];                 //  -5         -4      -3         -2          -1     console . log (fruits . slice ( -4 , -1 ));

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 >

JavaScript pop() Method

  Definition and Usage The  pop()  method removes (pops)  the last element  of an array. The  pop()  method changes the original array. The  pop()  method returns the removed 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 pop() Method</ h1 >   < script >     const myNumbers = [ 1 , 4 , 8 , 4 ];         console . log (myNumbers);     console . log (myNumbers . pop ());     console . log (myNumbers);           </ script > </ body > </ html >

JavaScript unshift() Method

  Definition and Usage The  unshift()  method adds new elements to  the beginning  of an array. The  unshift()  method overwrites the original array. Return Value Type Description A number The new length of the array. syntex array .unshift( item1 ,  item2 , ...,  itemX ) <! 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 unshift() Method</ h1 >   < script >     const fruits = [1, 4, 8, 4];     console . log (fruits . unshift ( 2 ));     console . log (fruits);   </ script > </ body > </ html >

JavaScript Array push() Method

 JavaScript Array push() Method -------------------------------------------------- Definition and Usage The  push()  method adds new items  to the end  of an array. The  push()  method changes the length of the array. The  push()  method returns the new length Syntax  array .push( item1 ,  item2 , ...,  itemX ) <! 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 push() Method</ h1 >   < script >     const fruits = [ "Banana" , "Orange" , "Apple" , "Mango" ];         // console.log(fruits.push("Pine Apple"));     // console.log(fruits); ...

JavaScript Array sort() Method

  Definition and Usage The  sort()  sorts the elements of an array. The  sort()  overwrites the original array. The  sort()  sorts the elements as strings in alphabetical and ascending order. For Number  Sort Compare Function Sorting alphabetically works well for strings ("Apple" comes before "Banana"). But, sorting numbers can produce incorrect results. "25" is bigger than "100", because "2" is bigger than "1". You can fix this by providing a "compare function" (See examples below) <! 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 >   < script >     const fruits = [ "...

JavaScript Array filter()

  Definition and Usage The  filter()  method creates a new array filled with elements that pass a test provided by a function. The  filter()  method does not execute the function for empty elements. The  filter()  method does not change the original array. syntex array .filter( function(currentValue, index, arr), thisValue ) thisValue =>   Optional. Default  undefined A value passed to the function as its  this  value. <! 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 filter() Method</ h1 >   < script >     const ages = [ 20 , 56 , 23 , 30 , 18 , 20 , 70 , 40 , 45 , 1...

JavaScript Find and FindIndex Method

    Want to understand Properly Plz see the video carefully on YouTube channel name is Adisma ------------------------------------------------------------------------ Definition and Usage The  find()  method returns the value of the first element that passes a test. The  find()  method executes a function for each array element. The  find()  method returns  undefined  if no elements are found. The  find()  method does not execute the function for empty elements. The  find()  method does not change the original array. ------------------------------------------------------------ The  findIndex()  method executes a function for each array element. The  findIndex()  method returns the index (position) of the first element that passes a test. The  findIndex()  method returns -1 if no match is found. The  findIndex()  method does not execute the function for empty array elements...

JavaScript includes() Method or Function

    Want to understand Properly Plz see the video carefully on YouTube channel name is Adisma ------------------------------------------------------------------------ The  includes()  method returns  true  if a string contains a specified string. Otherwise it returns  false . The  includes()  method is case sensitive. <! 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 >includes() Method</ h1 >   < script >     const myList = [ 1 , 2 , 3 , 5 , "seemaSharma" , "adisma" , "seema" ];     console . log (myList . includes ( "seema" ));   </ script > </ body > </ html ...

JavaScript lastIndexOf() method

  Want to understand Properly Plz see the video carefully on YouTube channel name is Adisma Definition and Usage The  lastIndexOf()  method returns the index (position) of the last occurrence of a specified value in a string. The  lastIndexOf()  method searches the string from the end to the beginning. The  lastIndexOf()  method returns -1 if the value is not found. The  lastIndexOf()  method is case sensitive. <! 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 >Searching In An Array = lastIndexOf () Method</ h1 >   < script >     const myFriends = [ "seema" , "Seema Sharma" , "Adisma" , ...

JavaScript indexOf() Method

    Want to understand Properly Plz see the video carefully on YouTube channel name is Adisma The  indexOf()  method returns the position of the first occurrence of a value in a string. The  indexOf()  method returns -1 if the value is not found. The  indexOf()  method is case sensitive. <! DOCTYPE html > < html lang = "en" > < head >   < meta charset = "UTF-8" >a   < 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 >Searching In An Array = indexOf() Method</ h1 >   < script >       const myFriends = [ "seema" , "Seema Sharma" , "Adisma" , "seema" , "Aditya" ];       console . log ( "Index Number =" + myFriends . indexOf ( "Adisma...

JavaScript forEach Method or Loop

  Want to understand Properly Plz see the video carefully on YouTube channel name is Adisma The  forEach()  method calls a function for each element in an array. The  forEach()  method is not executed for empty elements.   <! 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 forEach Loop / Method</ h1 >   < script >     var myNumbers = [ 2 , 5 , 8 , 10 , 30 ];   let sum = 0 ;     myNumbers . forEach ( function ( curVal , indexOfElement , curArr ){       console . log ( "Value = " + curVal , 'IndexNo= ' +   indexOfElement , "of array =" + curArr ); ...

JavaScript for in and for of Loop

    Want to understand Properly Plz see the video carefully on YouTube channel name is Adisma <! 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 >for in ... and for of ... Loop introduced in 2015(ES6)</ h1 >   < script >     var myFriends = [ "Seema" , "Vandana" , "Reema" , "Riyanshi" , "Nitya" ];     // console.log(myFriends.length); ///-------------------------   //  for(let i = 0 ;i<=myFriends.length-1 ;i++){   //   console.log(myFriends[i]);   //  }   // for( let elements in  myFriends){   //   console.log(elements);   // }   for ( let elements of my...

JavaScript Array : Another Way to create Array

Image
  Want to understand Properly Plz see the video carefully on YouTube channel name is Adisma Output : of   m yNumber[0]= 12;     myNumber[2] = 24;     myNumber[4] = 67;     myNumber[5] = 3; <! 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 >   < script >     var arr = [ 1 , 2 , 3 , "Seeema" , "Pooja" ]     var myNumber =   new Array ( 5 );     myNumber[ 0 ] = 12 ;     myNumber[ 2 ] = 24 ;     myNumber[ 4 ] = 67 ;     myNumber[ 5 ] = 3 ;     for ( let i = 0 ; i <= 5 ; i ++ ){      console . log (myNumber[i]);     ...