Q:

How to return previous and next element by element from array in JavaScript? 

I have an array and i want to return the next and previous elements by a given string. 
This is the array:
var array = [
      "11111",
      "22222",
      "343245",
      "5455",
      "34999",
      "34555",
    ];

The user inputs a random number, unknown number, and i have to find the next and previous elements based on the user' string. 
For example the User writes: 3499
And the return must be Previous element is 5455 and next element is 34555. 

A:

Use Array#indexOf method to get the index of the element and get other element based on the index. 

var array = [
  "11111",
  "22222",
  "343245",
  "5455",
  "34999",
  "34555",
];

var ele = "34999";

var index = array.indexOf(ele);

console.log('next', array[index + 1])
console.log('prev', array[index - 1])

