public
Created

Finding whether a value inputted by user exists in the given array

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
var fruits = ['apples', 'pears', 'bananas'];
 
console.log("Enter in a fruit name");
 
process.stdin.on('data', function(fruit) {
var fruitName = fruit.toString().replace("\n", "");
 
if (fruits.indexOf(fruitName) >= 0 ) {
console.log("The value has been found in the array");
process.exit(); }
 
else {
console.log("Value not found");
process.exit(); }
 
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.