From 901083d666146ae76fd22e811aa23b5bc933a77a Mon Sep 17 00:00:00 2001 From: Michiel Vanhoutte Date: Mon, 16 Nov 2020 21:12:18 +0100 Subject: [PATCH] "filter" instead of "map" to get only an array with one item fix requesting order with id 2 returns undefined --- src/understanding.mjs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/understanding.mjs b/src/understanding.mjs index 00bef6a..218cb96 100644 --- a/src/understanding.mjs +++ b/src/understanding.mjs @@ -40,13 +40,12 @@ export function callbacks() { xhr2.onload = () => { const order = JSON.parse(xhr2.responseText); - const description = statuses.map(t => { - if (t.id === order.orderStatusId) { - return t.description; + const status = statuses.filter(stat => { + return stat.id === order.orderStatusId } - })[0]; + )[0]; - setText(`Order Status: ${description}`); + setText(`Order Status: ${status.description}`); }; xhr2.send();