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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to get an array of the values of all properties of objects inside an array of objects?

How to get all the values and keys inside an array of objects separated with comma without inbuilt methods

How to get values from an array, inside another array, with stdClass Objects?

How to get all values from an array of objects with nested arrays of objects?

How to get all used values from all objects in array in ejs

How to get min values among properties inside an array of objects?

How to get values from specific objects inside an array?

How to get all objects inside an array JSON in a C# controller

How to get all objects of same type inside an array in Javascript?

How to get all unique objects (with two values) in an array?

How to get all values of a specific key in array of objects?

How to delete duplicate values of objects inside array?

How to access all objects inside array

How to compare values in an array, that is inside an array of objects, with a property of the objects?

How to get distinct values from an array of objects which has an Array inside in on one key and count JavaScript?

How can we get an array of values for a particular key, from a sequence of objects inside an array using Javascript

How to get all specific values from an array of objects with nested arrays of objects?

How to get all the values of a column inside a while loop and put those values into an array

Clickhouse - How can I get distinct values from all values inside an array type column

How to count all unique values in an array of objects?

get all values from array inside of another array

How to get values from one array of objects into another array of objects

How to get the values inside a nested JSON array

How to get values from an array inside a loop?

how to get json values inside an array in javascript

How To Get Values Out of An Array Inside Of A Class

How to get sum all elements inside array

How to get values from array of objects in javascript

How to get array of objects with unique values?