从一行阵列变换阵列到多个行阵列
有了一个循环,例如。
var object = { '0': [1, 2, 3, 4] }, // the object
result = function (o) { // the iife for the result
var r = {}; // the temporary variable
o['0'].forEach(function (a, i) { // the loop over the property zero
r[i] = a; // the assignment to the object with
}); // the wanted key
return r; // the return of the temporary object
}(object); // the start with the object
document.write('<pre>' + JSON.stringify(result, 0, 4) + '</pre>');
太棒了!谢谢 – user3241620
i have an array that returns the values like this:
0: 1,2,3,4
试试这个
"0: 1,2,3,4".split(":").pop().split(",").map(function(value){return [value]});
这不提供问题的答案。要批评或要求作者澄清,请在其帖子下方留言。 - [发表评论](/ review/low-quality-posts/11505767) –
@DanielCheung现在检查 – gurvinder372
你可以这样做:
var array = ['1,2,3,4'];
console.log(array[0].split(','));
我得到这个错误:Uncaught TypeError:sortOrderValues [0] .split不是函数 – user3241620
你可以做console.log(sortOrderValues )并给我输出,谢谢 – vvo
输入是'array'([1,2,3,4])或'object'({0:[1,2,3,4]})? – Rayon
它是一个对象 – user3241620