How to get all values of objects inside array

abdou

In my meteor app , this code

       var format = [];
       var formats = [];



        var length = result.formats.length - 1;
        for (var i = 0 ; i <= length; i++) {
          var type = result.formats[i].type;
          var type2 = type.split(/[;,]/);

              var typee = type2[0];
               var resolutions = result.formats[i].resolution;
               var urls = result.formats[i].url;


                format.push({
                  "Type": typee,
                  "resolution": resolutions
                  // "url": urls
                })


        };



        var formatt = JSON.stringify(format, null, 4);
        Session.set('format', JSON.stringify(format, null, 4));
        console.log(formatt);

give me this result

[
    {
        "Type": "video/webm",
        "resolution": "360p"
    },
    {
        "Type": "video/mp4",
        "resolution": "360p"
    },
    {
        "Type": "video/x-flv",
        "resolution": "240p"
    },
    {
        "Type": "video/3gpp",
        "resolution": "240p"
    },
    {
        "Type": "video/3gpp",
        "resolution": "144p"
    },
    {
        "Type": "video/mp4",
        "resolution": "360p"
    },
    {
        "Type": "video/webm",
        "resolution": "360p"
    },
    {
        "Type": "video/mp4",
        "resolution": "240p"
    },
    {
        "Type": "video/webm",
        "resolution": "240p"
    },
    {
        "Type": "video/mp4",
        "resolution": "144p"
    },
    {
        "Type": "video/webm",
        "resolution": "144p"
    },
    {
        "Type": "audio/webm",
        "resolution": null
    },
    {
        "Type": "audio/mp4",
        "resolution": null
    },
    {
        "Type": "audio/webm",
        "resolution": null
    },
    {
        "Type": "audio/webm",
        "resolution": null
    },
    {
        "Type": "audio/webm",
        "resolution": null
    } ]

How can I do to get only the values without parentheses; something like that

    "Type": "video/webm",
    "resolution": "360p"


    "Type": "video/mp4",
    "resolution": "360p"


    "Type": "video/x-flv",
    "resolution": "240p"


    "Type": "video/3gpp",
    "resolution": "240p"


    "Type": "video/3gpp",
    "resolution": "144p"


    "Type": "video/mp4",
    "resolution": "360p"


    "Type": "video/webm",
    "resolution": "360p"


    "Type": "video/mp4",
    "resolution": "240p"


    "Type": "video/webm",
    "resolution": "240p"


    "Type": "video/mp4",
    "resolution": "144p"


    "Type": "video/webm",
    "resolution": "144p"


    "Type": "audio/webm",
    "resolution": null


    "Type": "audio/mp4",
    "resolution": null


    "Type": "audio/webm",
    "resolution": null


    "Type": "audio/webm",
    "resolution": null


    "Type": "audio/webm",
    "resolution": null

I spent two days without solution :(

Thank's for you help

Edit: what I want to do is to retrieve an array of values or cursors used in {{#each}} in a template

     {#each format}} 
        <tr>

             {{> postItem}}


        </tr>
        {{/each}} 


<template name="postItem">

        {{Type}}
        {{resolution}} 
        {{url}}

</template>





Template.hello.helpers({


     format:function(){
     return Session.get('format');
    }

  });
Jagdish Idhate

This will work.

var arr = [{"Type":"video/webm","resolution":"360p"},{"Type":"video/mp4","resolution":"360p"},{"Type":"video/x-flv","resolution":"240p"},{"Type":"video/3gpp","resolution":"240p"},{"Type":"video/3gpp","resolution":"144p"},{"Type":"video/mp4","resolution":"360p"},{"Type":"video/webm","resolution":"360p"},{"Type":"video/mp4","resolution":"240p"},{"Type":"video/webm","resolution":"240p"},{"Type":"video/mp4","resolution":"144p"},{"Type":"video/webm","resolution":"144p"},{"Type":"audio/webm","resolution":null},{"Type":"audio/mp4","resolution":null},{"Type":"audio/webm","resolution":null},{"Type":"audio/webm","resolution":null},{"Type":"audio/webm","resolution":null}]

var output = arr.map(function(obj){
  return JSON.stringify(obj).replace(/{|}/g,'')
}).join('\r\n');

console.log(output);

will give below

"Type":"video/webm","resolution":"360p"
"Type":"video/mp4","resolution":"360p"
"Type":"video/x-flv","resolution":"240p"
"Type":"video/3gpp","resolution":"240p"
"Type":"video/3gpp","resolution":"144p"
"Type":"video/mp4","resolution":"360p"
"Type":"video/webm","resolution":"360p"
"Type":"video/mp4","resolution":"240p"
"Type":"video/webm","resolution":"240p"
"Type":"video/mp4","resolution":"144p"
"Type":"video/webm","resolution":"144p"
"Type":"audio/webm","resolution":null
"Type":"audio/mp4","resolution":null
"Type":"audio/webm","resolution":null
"Type":"audio/webm","resolution":null
"Type":"audio/webm","resolution":null

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

how to sum up all values with same keys in an object inside an array and get their average

분류에서Dev

Handlebars - How to render all values inside array to the template model?

분류에서Dev

How to get JSON response array all index values?

분류에서Dev

How to remove a simple specific key value pair from all objects inside an array

분류에서Dev

How to get values of a JSON array?

분류에서Dev

How to get all values from a list?

분류에서Dev

how to get all values of object via coffeescript?

분류에서Dev

Sum values inside an array

분류에서Dev

How to get the values of generic array in Java?

분류에서Dev

Getting all keys & their values from nested objects in JSON array (w/out jQuery)

분류에서Dev

Replace array values inside a document

분류에서Dev

How can I determine if all the values in an array are different, in Matlab

분류에서Dev

How to group by objects with inside objects with lodash?

분류에서Dev

How to get all the keys values from Redis Cache in C#?

분류에서Dev

How to get all the values of one column and calculate a total

분류에서Dev

How to access attributes of php object inside a array of php objects from javascript

분류에서Dev

Checking if all values are null inside an initialised object

분류에서Dev

if-check for all array values

분류에서Dev

How to send array values in a $.get call via jquery?

분류에서Dev

content of json array - how to get all elements using js

분류에서Dev

Get all sequences with current values

분류에서Dev

increasing values in numpy array inside out

분류에서Dev

Reduce Array to objects that share certain property: values

분류에서Dev

lodash/underscore find objects by key that is in values of array

분류에서Dev

lodash/underscore find objects by key that is in values of array

분류에서Dev

How can I merge two complex JSON objects with only unique or different values only showing in resultant array

분류에서Dev

How do I sort an array filled with objects, based on two values of the object?

분류에서Dev

How to access a property in array of objects without looping through all of them in php?

분류에서Dev

Java: How to I get values inside ArrayList when there's parent/child involved?

Related 관련 기사

  1. 1

    how to sum up all values with same keys in an object inside an array and get their average

  2. 2

    Handlebars - How to render all values inside array to the template model?

  3. 3

    How to get JSON response array all index values?

  4. 4

    How to remove a simple specific key value pair from all objects inside an array

  5. 5

    How to get values of a JSON array?

  6. 6

    How to get all values from a list?

  7. 7

    how to get all values of object via coffeescript?

  8. 8

    Sum values inside an array

  9. 9

    How to get the values of generic array in Java?

  10. 10

    Getting all keys & their values from nested objects in JSON array (w/out jQuery)

  11. 11

    Replace array values inside a document

  12. 12

    How can I determine if all the values in an array are different, in Matlab

  13. 13

    How to group by objects with inside objects with lodash?

  14. 14

    How to get all the keys values from Redis Cache in C#?

  15. 15

    How to get all the values of one column and calculate a total

  16. 16

    How to access attributes of php object inside a array of php objects from javascript

  17. 17

    Checking if all values are null inside an initialised object

  18. 18

    if-check for all array values

  19. 19

    How to send array values in a $.get call via jquery?

  20. 20

    content of json array - how to get all elements using js

  21. 21

    Get all sequences with current values

  22. 22

    increasing values in numpy array inside out

  23. 23

    Reduce Array to objects that share certain property: values

  24. 24

    lodash/underscore find objects by key that is in values of array

  25. 25

    lodash/underscore find objects by key that is in values of array

  26. 26

    How can I merge two complex JSON objects with only unique or different values only showing in resultant array

  27. 27

    How do I sort an array filled with objects, based on two values of the object?

  28. 28

    How to access a property in array of objects without looping through all of them in php?

  29. 29

    Java: How to I get values inside ArrayList when there's parent/child involved?

뜨겁다태그

보관