Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save softsolution/85f75c499dcce518e1a2 to your computer and use it in GitHub Desktop.
Save softsolution/85f75c499dcce518e1a2 to your computer and use it in GitHub Desktop.
Функции js для проверки значения в массиве, и ключей в массиве
//проверка наличия ключа в массиве
var arr = [1,2,3,4,5,6,7,8,9];
if(3 in arr) alert("Элемент с ключём 3 присутствует в массиве");
if(!(15 in arr)) alert("Элемента с ключём 15 нет в массиве");
//проверка наличия значения в массиве
var arr = [1,2,3,4,5,6,7,8,9];
if(in_array(6, arr)) alert("Значение 6 есть в массиве");
function in_array(value, array) {
for(var i = 0; i < array.length; i++) {
if(array[i] == value) return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment