Paste Search Dynamic
Recent pastes
containNumber
  1. function containNumber(numbers, number) {
  2.     for (let i in numbers) {
  3.         if (numbers.hasOwnProperty(i)) {
  4.             if (numbers[i] === number) {
  5.                 return true;
  6.             }
  7.         }
  8.     }
  9.     return false;
  10. }
  11.  
  12. let numbers = [1, 2, 3];
  13. let isContain2 = containNumber(numbers, 2);
  14. //isContain2 is true
  15.  
  16. let isContain4 = containNumber(numbers, 4);
  17. //isContain4 is false
  18.  
  19. console.log(`isContain2 is ${isContain2}`);
  20. console.log(`isContain4 is ${isContain4}`);
Parsed in 0.002 seconds