Created
April 8, 2017 07:16
-
-
Save Avesha-2016/66984af45e3cb9eeb6befb07e77c0a4d to your computer and use it in GitHub Desktop.
выборка из массива JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var libraryLetter = ["book", "car", "bank", "near", "between", "map", "dog"]; | |
var userLetter = prompt("Укажите слово"); | |
function inArray(arr, str) { | |
return arr.filter(function(item) { | |
return item.indexOf(str) !== -1 | |
}) | |
} | |
var words = inArray(libraryLetter, userLetter) | |
if (words.length > 0) { | |
console.log(words) | |
} else { | |
console.log('Совпадений не найдено') | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
поиск в массиве по заданному символу