Add key value pair to array - Javascript Array Operation

Javascript examples for Array Operation:Associative Array

Description

Add key value pair to array

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(){// w  ww .j a v a 2  s. c  o m
var mainForm = {
  'inputField[0]': 'test0',
  'inputField[1]': 'test1',
  'inputField[2]': 'test2',
  'inputField[3]': 'test3',
}
var inputField = [];
for (var val in mainForm) {
      inputField.push(mainForm[val]);
 }
 console.log(inputField);
    }

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

Related Tutorials