I just started working on Office app. In office 365 app, mostly we have to use client side scripting. So, i want to get cell values from excel. Somewhere, i need to define JavaScript array and get values from array in my code. hence, I have prepared JavaScript method to get values from array.
What is Jquery?
I don't want to explain overview about jQuery in this blog. Here is the nice explanation in following link.
jQuery Overview
How can we get array values from client side using jquery?
We can get array values using $.each method in jQuery. I have used jQuery version 1.10.2 js in following sample.
$.each() is a generic iterator function for looping over object, arrays, and array-like objects. Plain objects are iterated via their named properties while arrays and array-like objects are iterated via their indices.
// Declare array like following in javascript
var arr = ["Mahesh", "Praveen", "DJ", "Jignesh", "Vulpes"];
Code Snippet :
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>click demo</title>
  6. <!-- Declare Jquery -->
  7. <script src="Scripts/jquery-1.10.2.min.js"></script>
  8. <script src="Scripts/jquery-1.10.2.js"></script>
  9. <title></title>
  10. <script type="text/javascript">
  11. // Specify a function to execute when the DOM is fully loaded
  12. $(document).ready(function ()
  13. {
  14. // Call button click event
  15. $("#btnTest").click(function ()
  16. {
  17. // Declare array
  18. var arr = ["Mahesh", "Praveen", "DJ", "Jignesh", "Vulpes"];
  19. // Define jquery each loop to get value of array
  20. $.each(arr, function (index, value)
  21. {
  22. // Get value in alert
  23. alert(value);
  24. });
  25. });
  26. });
  27. </script>
  28. </head>
  29. <body>
  30. <input type="button" id="btnTest" value="GetValuefromArray" />
  31. </body>
  32. </html>
I have tested and it is working fine in Google Chorme 35.0.1916.153, Internet Explorer 11 and Firefor 29.0.1 browsers.
Output of sample code