3
Good morning!
I have the following array:
const keys = ["idCard1", "idCard2", "idCard3", "oi", "idCard4"]
I need to save in another array only what starts with the word "idCard", would be possible?
User attempt:
let keys = [idCard1, idCard2, idCard3, oi, idCard4]
let filtro = keys.filter(item => item.includes("idCard"));
console.log(filtro);
This attempt had been placed in the field of answers.
Function isBigEnough(value) { Return value >= 10; } var Filtered = [12, 5, 8, 130, 44]. filter(isBigEnough); // filtered is [12, 130, 44]
– Rebeca Nonato
But I want to take everything that starts with the word "idCard", this function would serve?
– Vitor Reis
This answers your question? Filter string array
– Rebeca Nonato
Let names = ["Thiago Carvalho", "Renata Carvalho", "Alexandre Otoni", "Guilherme Otoni de Carvalho"]; Let filter = names.filter(item => item.includes("Carvalho")); console.log(filter);
– Rebeca Nonato
Very quiet at this time, this here
const keys = [idCard1, idCard2, idCard3, oi, idCard4]
is not an array of strings, it is an array composed of the value of several variables that may or may not be strings.– Augusto Vasques
I posted the code test, which didn’t work
– Vitor Reis
I didn’t present a tentative, I don’t kick. I’m warning you that this is what you put in the question
const keys = [idCard1, idCard2, idCard3, oi, idCard4]
is not an array of strings is an array of variables.– Augusto Vasques
An array of strings would look like this
const keys = ["idCard1", "idCard2", "idCard3", "oi", "idCard4"]
. So I ask you are sure that the first form presented is correct?– Augusto Vasques
You are correct, my way of sending here was really wrong. My array is strings, but I brought it here as a variable. Still, I could find what I need?
– Vitor Reis
Edit the question and leave it in the correct way and mark me in a comment after the issue that when coming back from lunch I give you an answer. That’s if someone hasn’t already answered it after editing.
– Augusto Vasques
Ready, Augusto. I have already edited. I would appreciate it if you could help me. Thanks in advance
– Vitor Reis