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

162
Visualizações
How can you convert a List<Pair<String,String>> to List<String> in javascript?

This is the Output: The data structure for the output is Map<String, List<Pair<String, String>>>

    "testdata": [
        {
            "1.0": "True"
        },
        {
            "1.1": "False"
        }
]

Now I need to display this data on the UI as "testdata":["1.0","1.1","1.2"], wherein here from the Pair, I want to fetch only the first elements from the Pair and put them in the structure Map<String, List<String>>

So how do I write that code in javascript in order to get that output?

this.previousData = versions.filter(v => v !== this.version).map(item => ({ text: item, value: item }))

How do I modify this code to get this output "testdata":["1.0","1.1","1.2"]?

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

0

your question isn't too clear about which element you are struggling with

so to get the data

async getData()
{
    const resp = await fetch("<<your url from your java service>>" )
    return await resp.json();
}

to format the data as you wish it to be formatted

formatData(json){
    return json.testdata.map((i)=>Object.entries(i).map(([k,v])=>k)).flat()
}

and to display in vue

<template>testdata:{{testdata}}</template>
<script>
...
     methods:{
        async populatedata(){
            const tmp = await getData()
            this.testdata = formatData(tmp)
        }
     }
...
</script>

Object.entries will convert an object into a tuple array so {"1.0":"True","1.1":"False"} will become [["1.0","True"],["1.1":"False"]] which then lets you use tuple decomposition to get the keys

you could also use Object.keys() if you have no need for the values but that wasn't clear from the context so i gave you the more flexible option

about 4 years ago · Juan Pablo Isaza Relatório

0

You could try something like this:


// This assumes that there will be only one key in each array item, or the first key in each array item denotes the version

this.previousData = 
    versions
     .filter(v => v !== this.version)
     .map(item => Object.keys(item)[0])

// or as MikeT suggested, if you are only expecting something like this:
// [
//  { "v1": "some value 1" },
//  { "v2": "some value 2" },
//  ... in general --> { "version": "some value" }
// ]
// you may try this as well
this.previousData = 
    versions
     .filter(v => v !== this.version)
     .map(item => Object.keys(item))
     .flat()


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