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

143
Visualizações
Access nested property from another object in javascript

I am confused on how this code below has access to a nested property. The addLayer function takes in a object which has a nested property textfield which comes from the above addSource method's properties.storeId. I am confused on how the textfield can be written as {storeId}. The object is not destructed anywhere therefore how can it be written like this?

const loadmap = () => {
  map.on("load", () => {

    map.addSource("point", {
      type: "geojson",
      data: {
        type: "FeatureCollection",
        features: [
          {
            type: "Feature",
            geometry: {
              type: "Point",
              coordinates: [-71.157895, 42.707741],
            },
            properties: {
              storeId: "0001",
              icon: "store"
            },
          },
        ],
      },
    });

    map.addLayer({
      id: "points",
      type: "symbol",
      source: "point", // reference the data source
      layout: {
        "icon-image": "airfield-11", // reference the image
        "text-field": "{storeId}",
      },
    });
  });
};
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

{storeId} between double quotations is just a string,

otherwise it's a shorthand for

let object={storeId:storeId}

another example:

let name="erfan"
let obj = {name} /// equivalent to {name:name}
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