Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function update_array(str, slinger_array) {
  2.  
  3.     for (var i = 0; i < str.length(); i++) { // Loop through each character of the string
  4.  
  5.         if (slinger_array[i] == undefined) { // If array element does not exist yet, push new element
  6.  
  7.             slinger_array.push({
  8.                 "slinger_char": {
  9.                     "id": i,
  10.                     "character": str.charAt(i)
  11.                 }
  12.             });
  13.         }
  14.         else // if the array element exists, update only the character
  15.         {
  16.             slinger_array[i].character = str.charAt(i);
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement