I have this array below that consists of a simple array. What i'm trying to accomplish is to put a key id in front of every array value to achieve something like this ["id:a", "id:b","id:c","id:d"] is there a easy way to accomplish this? any help would be greatly appreciated thank you.
var test = ['a','b','c','d']
You can use .map():
var test = ['a', 'b', 'c', 'd'];
function setID(item, index) {
var fullname = "id: " + item;
return fullname;
}
var output = test.map(setID);
console.log(output);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With