1

I am getting an object in angular that looks like this:

quiz.js:129 m {$promise: Promise, $resolved: false} 439:"https://mysite.no/sites/default/files/styles/quiz_large/public/fields/question-image/istock_000059790188_large.jpg?itok=62PzCown" 679: "" 1379:"https://mysite.no/sites/default/files/styles/quiz_large/public/fields/question-image/istock_000000301688_medium.jpg?itok=poGpHb5c" 1529:"https://mysite.no/sites/default/files/styles/quiz_large/public/fields/question-image/istock_000011483027_large.jpg?itok=LJ3f0c-X" 2022:"https://www.mysite.no/sites/default/files/styles/quiz_large/public/fields/question-image/208458_thumbnail.jpg?itok=6AG_2XS3" $promise: Promise $resolved: true__proto__: Object 

I would need to make an array out of that data, but not sure how to make this.

4
  • add loop on your data and add one by one in one arrayCommentedAug 26, 2016 at 8:56
  • can you please elaborate a bit more? I am not sure about the above given code is a reported exception or the desired object you want to convert to an array.CommentedAug 26, 2016 at 8:57
  • 1
    Refer to this answer: stackoverflow.com/questions/684672/…CommentedAug 26, 2016 at 8:57
  • see the object is having number of entries, so add loop on all entries and add in array one by one.CommentedAug 26, 2016 at 8:59

2 Answers 2

1

What have you tried? This is one way of doing it, though the error your getting doesn't seem to point that this is the issue.

var arr = Object.keys(obj) .map(function(key) { return obj[key] }); 
    0

    You can lodash _.values(obj) this will creates an array of values of this object.

    Here is the documentation and here is the fiddle for the same.

    I hope this helps, Thanks.

    var obj = { 439:"https://mysite.no/sites/default/files/styles/quiz_large/public/fields/question-image/istock_000059790188_large.jpg?itok=62PzCown", 679: "", 1379:"https://mysite.no/sites/default/files/styles/quiz_large/public/fields/question-image/istock_000000301688_medium.jpg?itok=poGpHb5c", 1529:"https://mysite.no/sites/default/files/styles/quiz_large/public/fields/question-image/istock_000011483027_large.jpg?itok=LJ3f0c-X", 2022:"https://www.mysite.no/sites/default/files/styles/quiz_large/public/fields/question-image/208458_thumbnail.jpg?itok=6AG_2XS3" } console.log(_.values(obj)); 

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.