Posts

Showing posts from September, 2023

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"); ...