Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (c) 2012 [iPs]TeaM
- * Bruno da Silva (email@brunodasilva.com)
- * Checar e pegar a posição de uma string em uma array
- *
- * www.brunodasilva.com
- * www.ips-team.forumeiros.com
- */
- <script>
- var fruits = ["Banana", "Orange", "Apple", "Mango"];
- alert(strInArr(fruits, "Banana")); // 0
- alert(strInArr(fruits, "Kiwi")); // -1 (not exist in fruits)
- alert(strInArr(fruits, "Orange")); // 1
- function strInArr(arr, str) {
- for(i = 0, j = arr.length; i < j; i++) {
- if(arr[i] == str) {
- return i ;
- }
- }
- return -1;
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement