I have an array of strings. I want to convert it to an array of objects.
For example:
var x =['one','two','three'];
Is there way to convert it array of objects?
I have an array of strings. I want to convert it to an array of objects.
For example:
var x =['one','two','three'];
Is there way to convert it array of objects?
This is what I came up with.
function toObject(arr) {
var rv = {};
for (var i = 0; i < arr.length; ++i)
if (arr[i] !== undefined) rv[i] = arr[i];
return rv;
}
This returns an object with a property strings which is the array you pass in
function convertArrayToObject (array) {
var obj = {
"strings": array
}
return obj
}