Posts

Showing posts from April, 2023

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

JavaScript Array Introduction

Image
  An array is  a special variable, which can hold more than one value :  e.g. 1 const numbers = [2,4,10,5,15,3] e.g.  2 const  cars = ["Saab", "Volvo", "BMW"]; <! 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 </ h1 >   < script >     // var a = 10;     // var b = 20;     // var c = 'Seema';     // var a = '10, 20 , "Seema"'     // var myNumber = [10, 20, 30, 40, 50]     // document.write(myNumber);     // console.log(myNumber);     // document.write(myNumber[0] + "<br>")     //  document.write(myNumber[1]) ...