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

252
Visualizações
Why doesn't Lodash's map method work in implicit chains?

Given an object that looks like this:

let obj = { mytest: [{ mytest2: 123 }] }

I would have thought I could use the implicit chain like this:

_(obj).get('mytest').map('mytest2').value();

But I get an error:

VM922:1 Uncaught TypeError: mytest2 is not a function
    at Array.map (<anonymous>)
    at <anonymous>:1:22
(anonymous) @ VM922:1

It seems to expect the map parameter to be a function. If I use the explicit chain method then it does seem to work.

_.chain(obj).get('mytest').map('mytest2').value();
[123]

What's going on here? I'm using lodash 4.17.15.

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

0

The _(obj) is not an "implicit chain", it's a use-once object that wraps a value to make lodash functions available with method syntax. _(obj).get('mytest') is the same as _.get(obj, 'mytest'), and returns the raw [{ mytest2: 123 }] array. The .map method you're calling is not _.map, it's the array map method which requires a function argument. You also wouldn't need to call .value() on the return value.

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