How do I set an array as a parameter in JavaScript? [closed]

0

I've been trying a new function to my program, this program has the purpose of making it easier to search for elements within an array, all these elements are unique, one way to find them and deliver them is by a rank, giving two parameters in the endpoint (start and end) when the user sets the start value and the end value, the program returns the values between these two, perfect. But it also has another option where the user can specify only some elements of the array and thus only show these in the program ...

    
asked by Wayo 25.04.2018 в 21:25
source

1 answer

1

I did not fully understand your question, but what I managed to capture was that you need a function that allows you to find a value behind an array, or a subsection of that array, you can use find and slice.

var frutas = ['fresa', 'manzana', 'banana'];
var fresa = frutas.find(fruta => fruta === 'fresa');
var manzanaBanana = frutas.splice(1,2);
var banana = manzanaBanana.find(fruta => fruta === 'banana');
//Y para mostrar solo algunos elementos podrías utilizar la función filter
var fresaBanana = ['fresa', 'banana'];
var frutasVIP = frutas.filter(fruta => fresaBanana.indexOf(fruta) > -1);
    
answered by 25.04.2018 в 21:34