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');
}
});
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] 삭제
몇 마디 만하겠습니다