Posts

iterators and generators

 it is a loop where it doesn't print all values until we give command to print console . log ( "working" ) let   array =[ 1 , 2 , 3 , 4 , 5 ] let   itr = array [ Symbol . iterator ](); console . log ( itr . next ().value) console . log ( itr . next (). value ) console . log ( itr . next (). value ) console . log ( itr . next (). value ) console . log ( itr . next (). value ) console . log ( itr . next (). done ) if you want to dont print 2 and want to print other console . log ( itr . next ().value) itr . next (). value console . log ( itr . next (). value ) console . log ( itr . next (). value ) console . log ( itr . next (). value ) console . log ( itr . next (). done )

how to play audio using js

  console . log ( "working" ) var   audio  =  new   Audio ( 'audio.mp3' ); function   go (){ setTimeout (()  =>  {               audio . play ();           },  4000 ); }

regulkar expression

//padhne Tarika //regex accepts the string as mentioned in regular expression and apply the regular expression //functions and acts accordingly by looking the function working pattern //scans the string word by word console . log ( "working" ) let   regex = / ^ rajiv/    //if expression i.e string match with regex than it will gives true in down case else statement is executed  regex = /boy $ /   //if ends with boy than it gives true:in eg. else but if /ege$/ if statement execution regex = /r.ji/    //if there is any letter between a-z(only one could be any * / not necessarily be...

regular expression functions

 exac,test,match,search,replace //   /something/ gives only 1st place index of something position // console.log("working") // let reg= /rajiv/ // console.log(reg) // console.log(reg.source) // let str="is rajiv a good boy ? don't you know it rajiv" // let result=reg.exec(str) // console.log(result) // let result1=reg.exec(str) // console.log(result1) //output: ["rajiv", index: 3, input: "is rajiv a good boy ? don't you know it rajiv", groups: undefined] //   /something/g gives any position  index of something position // let reg= /rajiv/g // console.log(reg) // console.log(reg.source) // let str="is rajiv a good boy...

fetch api using async await

 1. fetching simple text file from local storage async   function   go (){      try  {          const   promiseobj =  await   fetch ( "data.txt" );      console . log ( promiseobj ) if  (! promiseobj . ok ) {      throw   Error ( promiseobj . statusText ) } else {      const   nextobj = await   promiseobj . text ()      console . log ( nextobj ) }     }  catch  ( error ) {          console . log ( error )     } } 2.fetching simple json file from local storage async   function   go (){      console . log ( "clicked" )      const   obj =   await   fetch ( "data.json" )      console . log ( obj )   ...

fetch api using promise then

1. to fetch text data from local storage        let   variable = document . getElementById ( "click" ) variable . addEventListener ( "click" , gg ) function   gg (){      console . log ( "clicked" )      const   promiseObj = fetch ( 'data.txt' )      console . log ( promiseObj )      promiseObj . then ( function ( data ){          console . log ( data )          if ( data . status != 200 ){             throw   Error ( data . statusText )         }          return   data . text ()     }). catch ( function ( error ){          console . log ( error )     }). then ( function ( f...

async and await

 it is nth. but changing final function of promise  function   add ( a , b ){      return   new   Promise ( function ( resolve , reject ){          setTimeout (() => {              console . log ( "hello" )              resolve ( a + b )         }, 2000 )     }) }; function   show ( ok ){      console . log ( "sfhljl" )      console . log ( ok ) } async   function   showfinal (){      let   var1 =  await   add ( 10 , 20 );      console . log ( var1 )      let   var2 = await   multiply ( var1 );      console . log ( var2 ) } showfinal () console . log ( "end" )