0

im trying to access an object with the following structure:

_res:{ merchant_1: value, merchant_2: value, merchant_3: value,}

What i want is to be able to plug a for loop index value as follow to get each property like : "merchant_1", "merchant_2"...:

    for (let j = 0; j < 9; j++) {
          if (_res.merchant_ + `%j` != null) {
            var merchantName = _res.merchant_ + `%j`;
            var arbitrageVal = parseFloat(p_amz - price).toFixed(2);
            setRowsSub((prevRows) => [
              ...prevRows,
              createData(merchantName, availability, price, arbitrageVal, 'jesus')
            ]);
          } else {
            j = 9;
          }
        }
  • 1
    Your object structure has a massive code smell. Why not `_res: [{ merchant: value }, { merchant: value }, { merchant: value}]`? Appending numbers to variable names is almost always a beginner mistake due to lack of knowledge of how to work with arrays. – connexo Nov 18 '22 at 19:33
  • I miss spelled, you jsut wrote the structure i have – Ted's Projects Nov 18 '22 at 19:40

0 Answers0