Check every char in a string and return array element on corresponding position - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Check every char in a string and return array element on corresponding position

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from w ww  .  ja va  2  s  .c  o  m

var mystring = "010101", myarray =["A","B","C","D","E","F"], result = [];

for(var i=0;i<mystring.length;i++){
    if(mystring[i] != 0){
     result.push(myarray[i]);
    }
}
console.log(result);


    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials