I have array in javascript. I want that when i enter any index of array in text field it should return the value of that array and display it i am using following code
<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to extract the second and the third elements from the array.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
var bb=document.getElementById('input_field').value;
var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango","Apple"];
var citrus = fruits.slice(bb,4);
var x=document.getElementById("demo");
x.innerHTML=citrus;
}
</script>
<input type="text" id="input_field">
</body>
</html>
but problem is that if i enter 2 in text field then it shows Lemon but when i enter three it shows only one Apple but it should show two because there are two Apple in the array so i want that if there are two then show two like wise.