I need to change an array into an object using javascript
For an example. I have an array which looks like :
colours [
["black","red",shades : ["0","1","2"]]
]
I want to change this to :
colours [
{
"black","red", shades : ["0","1","2"]
}
]
Can anyone please tell me how I can do this using javascript code.
答案 0 :(得分:1)
var arr = $.map(obj, function(el) { return el; });
This question is been asked.
答案 1 :(得分:1)
function toObject(arr) {
var rv = {};
for (var i = 0; i < arr.length; ++i)
rv[i] = arr[i];
return rv;
}
Try to read this