Advertisement
Guest User

string

a guest
Dec 13th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. txt = 'avi, moshe, aharon, levi, itzik, keren, mor, MosHe, noy, david'
  2. var x = txt.split(", ")
  3.  
  4. for (index = 0; index < x.length; index++) {
  5.     if (x[index] == "keren") {
  6.         x[index] = "liron"
  7.     }
  8. }
  9.  
  10.  
  11. // show index from 1 to 4
  12. //alert(x.slice(0, 4))
  13.  
  14. // print last index
  15. alert(x.slice(-1))
  16.  
  17. // number of names in the list
  18. alert(x.length)
  19.  
  20. //replace all 'moshe' in list to 'eli'
  21.  
  22. for (index = 0; index < x.length; index++) {
  23.     if (x[index].toLowerCase() == "moshe") {
  24.         x[index] = "eli"
  25.     }
  26. }
  27. alert(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement