0

I have json with name like:

product_1
product_2
product_3

Could I have loop with variable + number?

My problem is: json.subject__ + (i + 1)

const json = items[0].json["data"];

var count = json.count;

var subject = [];
for (i = 0; i < count; i++) {
  subject[i] = json.subject__ + (i + 1);
}

My json structure like this:

[
  {
    "data": {
      "use_for": "website",
      "product__1": "bai 1",
      "length__1: "option 1",
      "product__2": "bai 2",
      "length__2": "option 2",
      "product__3": "bai 3",
      "length__3": "option 3",
      "format__3": [
         "sss",
         "kkk", ...
cmdntd
  • 11
  • 4

1 Answers1

1

You can use bracket notation for that:

subject[i] = json["subject__" + (i + 1)];
Sebastian Kaczmarek
  • 8,120
  • 4
  • 20
  • 38