vendredi 8 mai 2015

How to check an input words against several arrays in Javascript

I need to test all the words entered into an input against 3 objects and determine which array they belong to so I can output a URL to an API. I want to achieve this with Javascript/jQuery.

For example if the input had these words: keyword1 keyword2 keyword3 keyword5

All keyword entries will be added from a autocomplete plugin.

I then need to test them against 3 arrays.

var array1 = ["keyword2", "keyword6"];
var array2 = ["keyword3", "keyword4"];
var array3 = ["keyword1", "keyword5"];

I need to determine what array they came from so I can output a URL and add the values to specific keys in a URL.

Example:

http://ift.tt/1ceVdFc [insert keyword(s)] &array2= [insert keyword(s)] &array3= [insert keyword(s)]

The keywords need to be sent as an array and must have spaces replaced with dashes.

I am using jQuery to perform a GET request with the URL generated.

Aucun commentaire:

Enregistrer un commentaire