Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
153
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.                 "id": i,
  9.                 "value": str.charAt(i)
  10.             });
  11.         }
  12.         else // if the array element exists, update only the character
  13.         {
  14.             slinger_array[i].value = str.charAt(i);
  15.         }
  16.     }
  17.  
  18.     slinger_array.length = str.length; // change length to str.length to clear out excess characters
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement