0

I just built an assessment application, and this is saved answer.

{"2":"E","4":"C","5":"A"}

I meant the user just answered number 2, 4 and 5. Then I wanted to parse each answered in this format

  1. Not answered
  2. E
  3. Not answered
  4. C
  5. A
  6. Not answered

Any ideas how to parse it?

4
  • 3
    Have you tried something? Commented May 5, 2013 at 10:10
  • what language are you working in? Commented May 5, 2013 at 10:11
  • 2
    The title doesn't seem to have anything to do with the question. Commented May 5, 2013 at 10:15
  • I've fixed it using jquery. I loop and print 'Not Answered' when it's undefined. Commented May 6, 2013 at 2:45

1 Answer 1

2
var obj = {
    "2": "E",
    "4": "C",
    "5": "A"
};

for (var i = 1, size = 6; i <= size; i++) {
    console.log(i +'. '+ (obj[i] || 'Not answered'));
}

http://jsfiddle.net/vrhTA/

Sign up to request clarification or add additional context in comments.

1 Comment

thanks anyway. I've already fixed it. I looped trough the problems.length and print Not Answered when it's undefined

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.