Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
how to return an object from a key

I am trying to return an object based on a key, I managed to do that with the method below but still, I am wondering how to return the key and value 250: [176916, 176922, 176939], instead of the value only [176916, 176922, 176939]

const myObj = {
  250: [176916, 176922, 176939],
  325: [244050],
  400: [177100],
  500: [166743],
  700: [387789],
};

let arrAcceptedValues = [];
let notArrAcceptedValues = [];
const acceptedValues = ["250", "400"];

Object.keys(myObj).forEach((key) => {
  acceptedValues.includes(key)
    ? arrAcceptedValues.push(...myObj[key])
    : notArrAcceptedValues.push(...myObj[key]);
});

console.log({ arrAcceptedValues, notArrAcceptedValues });

//arrAcceptedValues result: [{250: [176916, 176922, 176939]}, {400: [177100]}]

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Maybe this helps:

const myObj = {
  250: [176916, 176922, 176939],
  325: [244050],
  400: [177100],
  500: [166743],
  700: [387789],
};

let arrAcceptedValues = [];
let notArrAcceptedValues = [];
const acceptedValues = ["250", "400"];
Object.entries(myObj).forEach(([key,value]) =>{
    acceptedValues.includes(key)
    ? arrAcceptedValues.push({[key]: value})
    : notArrAcceptedValues.push({[key]: value});
});

console.log({arrAcceptedValues , notArrAcceptedValues })

about 4 years ago · Juan Pablo Isaza Denunciar

0

    Object.keys(myObj).forEach((key) => {
  acceptedValues.includes(key)
    ? arrAcceptedValues.push({ key: myObj[key]})
    : notArrAcceptedValues.push({ key: myObj[key]});
});

this will work for your case

about 4 years ago · Juan Pablo Isaza Denunciar

0

Instead of using Object.keys, you could use Object.entries this is an easy way of getting the key & the value.

eg..

const myObj = {
  250: [176916, 176922, 176939],
  325: [244050],
  400: [177100],
  500: [166743],
  700: [387789],
};

let arrAcceptedValues = {};
let notArrAcceptedValues = {};
const acceptedValues = ["250", "400"];

Object.entries(myObj).forEach(([key, value]) => {
  acceptedValues.includes(key)
    ? arrAcceptedValues[key] = value
    : notArrAcceptedValues[key] = value;
});

console.log({ arrAcceptedValues, notArrAcceptedValues });

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda