2

I'm having some trouble on displaying data from a JSON file like this one:

Currently "checked": null. I want to do checked = true in steps array using the forEach loop.

Here is my JSON data:

{
  "id": 4,
  "process": {
    "id": 24,
    "name": "test-1Process",
    "description": "Unknown",
    "steps": [
      {
        "id": 6,
        "title": "test1-process",
        "description": "test1 FDescriptin",
        "assetURL": "",
        "checked": null
      },
      {
        "id": 7,
        "title": "test1-step2",
        "description": "step2 description",
        "assetURL": "",
        "checked": null
      }
    ],
    "possibleEndStates": [
      {
        "id": 1,
        "name": "test2-tesp2"
      },
      {
        "id": 1,
        "name": "test2-tesp2"
      }
    ]
  },
  "user": {
    "id": 5,
    "firstname": "john",
    "surname": "edd",
    "email": "[email protected] ",
    "companyAdministrator ": false,
    "roles ": [
      {
        "id ": 2,
        "name ": "test1 - role ",
        "department ": {
          "id ": 2,
          "name ": "test1 - department ",
          "description": null,
          "company": {
            "id": 2,
            "name": "sd",
            "address": "default",
            "timezoneId": "default",
            "logoURL": "default"
          }
        }
      }
    ]
  }
}

Then push in a steps variable steps array. Please, give me some suggestions.

2

3 Answers 3

2

Currently "checked": null I want to checked = true in steps array using foreach loop

try

data.process.steps.forEach(function(val){
  val.checked = true;
});
Sign up to request clarification or add additional context in comments.

Comments

1

Try this-

function changeKeyVal(element, index, array) {
   array[index]["checked"] = 'Value Renewed '+index;
  console.log(array[index]["checked"]);
}
data.process.steps.forEach(changeKeyVal);

Comments

0

You can also make use of Angular's in-built iterator since you are using Angular:

angular.forEach(data.process.steps, function(step) {
    step.checked = true;
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.