Search within two arrays

0

The case is the following. I have a script I wanted to use and as with all the questions "I suppose" I do not know how to do it. I am trying to do a search of array data with javascript "because they do not suggest other languages if your answer is not in javascript please do not reply" inside another array like this:

I have the array length:

var comprimentos = new Array('OI', 'OLA', 'IAI', 'BLZ', 'TESTE', 'TUDO BEM', 'JOIA');

but to cover all options such as 'hi?' which is different from 'hi' due to interrogation I created a second array

var int = new Array('?', '!', '');

So I thought of something like this:

var comprimentos = new Array('OI'+int[y], 'OLA'+int[y], 'IAI'+int[y], 'BLZ'+int[y], 'TESTE'+int[y], 'TUDO BEM'+int[y], 'JOIA'+int[y]);

where var y is a random number ranging from 0 to 2

but I have to confirm several times the code is giving a lot of error help me there

    
asked by anonymous 12.09.2017 / 19:58

1 answer

3

To get all the occurrences of the concatenation of the 2 arrays, simply unite them in this way ...

var comprimentos = new Array('OI', 'OLA', 'IAI', 'BLZ', 'TESTE', 'TUDO BEM', 'JOIA');

var int = new Array('?', '!', ' ');

var ocorrencias = [];

comprimentos.forEach(function(c){
  ocorrencias.push(c);
  int.forEach(function(i){
    ocorrencias.push(c+i);
  });
});

console.log(ocorrencias);
    
12.09.2017 / 20:18