score:1

Accepted answer
const obj = {
  "001": [18.180555, -66.749961],
  "002": [18.361945, -67.175597],
  "003": [18.455183, -67.119887],
};

let findKey = "002";
const arr = obj[findKey];
if (arr) {
  const [lat, long] = arr;
  console.log(lat, long);
}

let findKey2 = "004";
const arr2 = obj[findKey2];
if (arr2) {
  const [lat2, long2] = arr2;
  console.log(lat2, long2);
}

score:1

[lat, lng] = myJSON[findKey]
console.log(myJSON[findKey], lat, lng)

score:1

const obj = {"001":[18.180555,-66.749961],"002":[18.361945,-67.175597],"003":[18.455183,-67.119887]};

const [lat, long] = obj?.["002"] ?? [,]
console.log(lat, long)

const [nLat, nLong] = obj?.["004"] ?? [,]
console.log(nLat, nLong)

score:1

const obj = {
    '001': [18.180555, -66.749961],
    '002': [18.361945, -67.175597],
    '003': [18.455183, -67.119887],
};

const find_key = '002';
const [lt, lg] = typeof obj[find_key] == 'undefined' ? ['not exist', 'not exist'] : obj[find_key];

console.log(lt, lg);

Related Query

More Query from same tag