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

243
Vistas
Is there a way to find a value by knowing his position in the JSON array?

I'm very bad at coding, so probably this will be the most stupid question possible. I want to find a certain value in a JSON by his position in the array. The problem is that the IDs of the elements aren't sorted but they are 'random' numbers (See the photo). My question is, how can I read a certain value from an element by his position in the array? For example the ID 1001 is in position 0 etc... If I use json['data'][1001][...] i can read separately it but it's difficult to write them using a for cicle.

The JSON is LINK

 function myFunction() {
  
  var response = UrlFetchApp.fetch("http://ddragon.leagueoflegends.com/cdn/"+12.5+".1/data/en_US/item.json");
  var content = response.getContentText();
  var json = JSON.parse(content);
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("ITEMS");
  var items = sheet.getActiveRange();
  var itemsPosition = Object.keys(json['data']);
  Logger.log(json['data'][1001]['name']); //works with IDs, I obtain 'Boots'
  Logger.log(json['data'][0]['name']); // doesnt work with position
  Logger.log(json['data'[0]['name']); // doesnt work
}

Photo

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

0

Iterating through obj that came from JSON and retrieving name values

function listallnames() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Sheet name");
  const obj = JSON.parse("Your string");
  let vo = obj.data.map(o => [o.name]);
  sh.getRange(1,1,vo.length,vo[0].length).setValues(vo):
}
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