exam questions

Exam 70-480 All Questions

View all questions & answers for the 70-480 exam

Exam 70-480 topic 4 question 82 discussion

Actual exam question from Microsoft's 70-480
Question #: 82
Topic #: 4
[All 70-480 Questions]

You have the following code:

You need to convert objStr into an array.
Which line of code should you use?

  • A. var jsObject = Array.bind(objStr);
  • B. var jsObject = Array.valueOf(objStr);
  • C. var jsObject = JSON.parse(objStr);
  • D. var jsObject = $.makeArray(objStr);
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️
https://www.w3schools.com/js/js_json_parse.asp

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
AnetteK
4 years, 5 months ago
yeah seems weird but I guess this is the reason why it works: "When using the JSON.parse() on a JSON derived from an array, the method will return a JavaScript array, instead of a JavaScript object."
upvoted 1 times
...
Bart_v_M
4 years, 6 months ago
Okay, I now also tested C. And I have to admit that this should be the correct answer. I didn't expect this at first because the string "[1, 2, 3, 4]" is not in Javascript Object Notation, like '{ "name":"James", "age":34, "city":"Jamestown"}'. Below you can see my test code: <script> var objStr = "[1, 2, 3, 4]"; var json = JSON.parse(objStr); for (var i in json) { alert(json[i]); } </script>
upvoted 1 times
...
Bart_v_M
4 years, 6 months ago
I think answer D should be the correct answer, not C. See: https://api.jquery.com/jquery.makearray/
upvoted 1 times
Bart_v_M
4 years, 6 months ago
I've tested it and it does create an array, however it doesn't automatically split the elements (the numbers) in the string, of course...
upvoted 1 times
Bart_v_M
4 years, 6 months ago
Therefore you could use the following JavaScript: <script src="../jquery.js"></script> <script> window.onload = function () { var objStr = "[1, 2, 3, 4]"; var jsObject = $.makeArray(objStr.replace("[", "").replace("]", "").split(", ")); alert($.isArray("jsObject is array: " + jsObject)); for (var i in jsObject) { alert(jsObject[i]); } } </script>
upvoted 1 times
...
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...