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

153
Visualizações
How do you check if value exist in object of object's array?

I want to know which logic i should use to check every object's array of parent object contained in grand parent object

Hi guys i want to check if this value for example : "127.0.0.1" exists in this object (MyObject has like 2k objects in it)

{
  "name" : MyObject
  "value": [
      {
        "name" : "Object1",
        "properties":{
          "address" : [
             "13.65.25.19/32",
             "13.66.60.119/32",
           ]
         }
      },
      {
        "name" : "Object2",
        "properties":{
          "address" : [
             "13.65.25.19/32",
             "127.0.0.1",
           ]
         }
      }
    ]
}

Btw does include() needs to match the whole string or for example if 127.0.0.1 is like this in my object 127.0.0.1/32, i can still retrieve it even if there is a ip range ?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Your data is structured quite specifically, so you can write a custom method which you can call over and over again. It will check for a

const obj = {
    name: 'MyObject',
    value: [
        {
            name: 'Object1',
            properties: {
                address: ['13.65.25.19/32', '13.66.60.119/32'],
            },
        },
        {
            name: 'Object2',
            properties: {
                address: ['13.65.25.19/32', '127.0.0.1'],
            },
        },
    ],
};

const address = '127.0.0.1';

const includesAddress = (address) => {
    for (const val of obj.value) {
        if (val.properties.address.some((a) => address === a)) return true;
    }
    return false;
};

console.log(includesAddress(address));

about 4 years ago · Juan Pablo Isaza Relatório

0

Array.flatMap implementation

const obj = {
  name: 'MyObject',
  value: [
    {
      name: 'Object1',
      properties: {
        address: ['13.65.25.19/32', '13.66.60.119/32'],
      },
    },
    {
      name: 'Object2',
      properties: {
        address: ['13.65.25.19/32', '127.0.0.1'],
      },
    },
  ],
};

const address = '127.0.0.1';
const output = obj.value.flatMap(item => item.properties.address).includes(address);
console.log(output);

If you want check if the partial ip addess is included in the list, you should make use of a regex implementation.

Sample Implementation

const obj = {
  name: 'MyObject',
  value: [
    {
      name: 'Object1',
      properties: {
        address: ['13.65.25.19/32', '13.66.60.119/32'],
      },
    },
    {
      name: 'Object2',
      properties: {
        address: ['13.65.25.19/32', '127.0.0.1'],
      },
    },
  ],
};

const address = '13.65.25.19';
const regex = new RegExp(address, 'i')
const output = obj.value.flatMap(item => item.properties.address).filter(x => regex.test(x)).length > 0;
console.log(output);

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