I have an array like this:
[link1,link2,link3]
But I want it like this:
[uri:link1,uri:link2,uri:link3]
Please guide me over this. Thanks.
If you need in the form of (Array of objects)
var test = ['a', 'b', 'c', 'd'];
function setID(item, index) {
var fullname = {"id: ": item};
return fullname;
}
var output = test.map(setID);
console.log(output);
output: [ { "id: ": "a" }, { "id: ": "b" }, { "id: ": "c" }, { "id: ": "d" } ]
[uri:link1,uri:link2,uri:link3]is not valid JavaScript we don't really know what result you really want. So you want[{uri: link1}, {uri: link2}, ...]or{uri1: link1, uri2: link2, ...}? Having an array of objects with a single property is a bit unusual but of course might be necessary. Please provide more context about what you are actually trying to achieve.