[英]how to convert nested array of arrays into comma separated string
I have a object with 2 nested objects. 我有一个有2个嵌套对象的对象。 they are both a array of arrays.
它们都是一个数组数组。 I need to join the values of both into a comma separated string.
我需要将两者的值连接成逗号分隔的字符串。 Javascript, jquery or linqjs will be fine.
Javascript,jquery或linqjs会好的。 I got a start on it but I am stuck.
我开始了,但我被卡住了。 here is a plunker plunker
这是一个掠夺者的掠夺者
I need to take the data and product values and join them. 我需要获取数据和产品值并加入它们。 the end result needs to look like this
最终结果需要看起来像这样
newString = "Product-1, 3500, 2000 | Product-2, 5400, 1800 | etc.."
newString =“Product-1,335,2000 | Product-2,5400,1800 | etc ..”
json object json对象
var userDefinedSeries = {"style":"normal","color":"rgb(0, 0, 255)","width":4,"uid":[["425780c9-9727-4c5d-9bc4-65ce3334b0aa"],["06a8a24e-6a59-43e0-89a4-9fe4db55cac5"],["e1c73a33-ba2c-4d8d-9751-3c336442da84"]],"data":[[2500,50000],[2500,40000],[3000,40000]],"product":[["Product 3"],["Product 1"],["Product 2"]],"name":"Subject Property","type":"scatterLine","$$hashKey":"object:91"};
what i am working with 我在做什么
var newString = [];
var string;
var modifiedNames = userDefinedSeries.data.map(function(arrayCell) {
for (var key in userDefinedSeries.data){
for (var keyP in userDefinedSeries.product){
string = arrayCell[0] + " , " + arrayCell[1] + "|";
}
}
newString.push(string);
return string;
});
console.log(newArray);
Please check: Plunker 请检查: Plunker
var newString = [];
var modifiedNames = userDefinedSeries.product.map(function(product, index) {
var productString = product.map(function (p) {
return p.replace(" ", '-');
}).join(' ');
newString.push(productString + ', ' + userDefinedSeries.data[index].join(', '));
});
console.log(newString.join(' | '));
With the following code I got this output: 使用以下代码我得到了这个输出:
Product-3,2500,50000 |
产品-3,2500,50000 | Product-1,2500,40000 |
产品-1,2500,40000 | Product-2,3000,40000
产品2,3000,40000
var userDefinedSeries = {
"style":"normal",
"color":"rgb(0, 0, 255)",
"width":4,
"uid":[["425780c9-9727-4c5d-9bc4-65ce3334b0aa"],["06a8a24e-6a59-43e0-89a4-9fe4db55cac5"],["e1c73a33-ba2c-4d8d-9751-3c336442da84"]],
"data":[[2500,50000],[2500,40000],[3000,40000]],
"product":[["Product 3"],["Product 1"],["Product 2"]],
"name":"Subject Property","type":"scatterLine","$$hashKey":"object:91"};
var newString = [];
var string;
var key = 0;
userDefinedSeries.product.map(function(arrayCell) {
string = arrayCell + "," + userDefinedSeries.data[key];
string = string.replace(" ","-");
newString.push(string);
key++;
});
console.log(newString.join(" | "));
var newString = "";
for(var i=0; i< userDefinedSeries.uid.length;i++){
newString += userDefinedSeries.product[i];
newString += ","+userDefinedSeries.data[i];
newString += "|";
}
console.log(newString);// your required string
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.