Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Avesha-2016/66984af45e3cb9eeb6befb07e77c0a4d to your computer and use it in GitHub Desktop.
Save Avesha-2016/66984af45e3cb9eeb6befb07e77c0a4d to your computer and use it in GitHub Desktop.
выборка из массива JS
<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>
@Avesha-2016
Copy link
Author

поиск в массиве по заданному символу

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment