1. <script>
    2. function strStr(haystack, needle){
    3. if(needle == null){
    4. console.log(-1)
    5. return -1
    6. }else{
    7. if(haystack.includes(needle)){
    8. console.log(haystack.indexOf(needle))
    9. return haystack.indexOf(needle)
    10. }else{
    11. console.log(-1)
    12. return -1
    13. }
    14. }
    15. }
    16. var haystack="hello"
    17. var needle = "ll"
    18. strStr(haystack, needle)
    19. </script>