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 get the combination of array values from nested arrays in an array of objects

分類Dev

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

分類Dev

How to get all keys with values from nested objects

分類Dev

How to parse json to get all values of a specific key within an array?

分類Dev

How to get JSON response array all index values?

分類Dev

Sum values of objects which are inside an array with underscore.js and reduce

分類Dev

ActiveRecord get all Post inside array of categories with all their categories

分類Dev

How can I check if the array of objects has duplicate property values and get the last value that is repeated?

分類Dev

How to update multiple values with an array inside Reducer

分類Dev

How to put values of objects from an array into a string

分類Dev

filter array of objects with underscore and get new array of values

分類Dev

How do i filter an array inside of a array of objects?

分類Dev

How to get text values to an array?

分類Dev

How to get all array edges?

分類Dev

How to get unique an array of objects back from a complex an array of objects?

分類Dev

How to get values in array of array in angular?

分類Dev

How to get the size of an element inside an array?

分類Dev

how to get local characters inside json array

分類Dev

How to get an Array of Objects from Firestore in Swift?

分類Dev

How to search for a value in array of objects and get it in Laravel?

分類Dev

How to count all values in a multidimensional array?

分類Dev

Get union of keys of all objects in js array using reduce

分類Dev

How to find sum objects inside an array using mongoose ,node ,

分類Dev

How to find sum objects inside an array using mongoose ,node ,

分類Dev

How to get all values in a string enum?

分類Dev

how to get all values of object via coffeescript?

分類Dev

How to get objects from inside a block and use it in another class or method?

分類Dev

How to Return Enum objects with all properties from Enum values in Java

分類Dev

How to get an array of counts of specific objects in an existing array?

Related 関連記事

  1. 1

    How to get the combination of array values from nested arrays in an array of objects

  2. 2

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

  3. 3

    How to get all keys with values from nested objects

  4. 4

    How to parse json to get all values of a specific key within an array?

  5. 5

    How to get JSON response array all index values?

  6. 6

    Sum values of objects which are inside an array with underscore.js and reduce

  7. 7

    ActiveRecord get all Post inside array of categories with all their categories

  8. 8

    How can I check if the array of objects has duplicate property values and get the last value that is repeated?

  9. 9

    How to update multiple values with an array inside Reducer

  10. 10

    How to put values of objects from an array into a string

  11. 11

    filter array of objects with underscore and get new array of values

  12. 12

    How do i filter an array inside of a array of objects?

  13. 13

    How to get text values to an array?

  14. 14

    How to get all array edges?

  15. 15

    How to get unique an array of objects back from a complex an array of objects?

  16. 16

    How to get values in array of array in angular?

  17. 17

    How to get the size of an element inside an array?

  18. 18

    how to get local characters inside json array

  19. 19

    How to get an Array of Objects from Firestore in Swift?

  20. 20

    How to search for a value in array of objects and get it in Laravel?

  21. 21

    How to count all values in a multidimensional array?

  22. 22

    Get union of keys of all objects in js array using reduce

  23. 23

    How to find sum objects inside an array using mongoose ,node ,

  24. 24

    How to find sum objects inside an array using mongoose ,node ,

  25. 25

    How to get all values in a string enum?

  26. 26

    how to get all values of object via coffeescript?

  27. 27

    How to get objects from inside a block and use it in another class or method?

  28. 28

    How to Return Enum objects with all properties from Enum values in Java

  29. 29

    How to get an array of counts of specific objects in an existing array?

ホットタグ

アーカイブ