Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
find a word inside array propety inside object

How can i iterate this object, and his properties that have arrays, to fin a word that is inside of array, for example beats

[
  {
    mouse: 'lenovo',
    teclado: 'dell',
    monitor: 'hp',
    headset: ['audioTechnica', 'klipXtreme', 'beats']
  },
  {
    mouse: 'razor',
    teclado: 'think pad',
    monitor: 'lg',
    headset: ['random', 'hyperx', 'jbl']
  },
  {
    mouse: 'technet',
    teclado: 'red dragon',
    monitor: 'benq',
    headset: ['sony', 'senheiser', 'toshiba']
  }
]
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You want to find object in this array, which properties has some string, correct?

If that's what you are looking for, here is some quick tip: you should iterate over array (maybe, using "find") and then for each object iterate over it's props, and then check if it has a string you are looking for.

Implementation example:

let searchPhrase = 'razor';

array.find(item => {
  Object.keys(item).find(key => typeof item[key] === 'string' ? 
    item[key] === searchPhrase : 
    item[key].includes(searchPhrase)
  )
)

Please be aware that this code relies on the fact that the object's properties are only string or array. If you are not sure about that fact, some additional checks required.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use recursion to traverse over all object levels:

const trav = (obj) => {
  if (obj instanceof Array) {
    obj.forEach(item => trav(item))
  } else if (typeof obj === "object") {
    Object.keys(obj).forEach(key => {
      trav(obj[key])
    })
  } else if(typeof obj === "string"){
    if(obj === "beats") {
      console.log('Find it')
    }
  }
}

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda