It's not really clear whether you need an object or an array, so here's a couple of examples that show both. These examples are in ES6. I can rewrite them in ES5 if you're not familiar with the syntax.
Both examples assume that there is a class called link on the input elements (to differentiate them from any other inputs you might have).
<input class="link" value="sdfs" />
1) Array DEMO
Pick up the inputs and iterate over them with map:
function getLinks() {
const links = document.querySelectorAll('.link');
return [...links].map(link => link.value);
}
OUTPUT
[ "sdfs", "34", "min", "987" ]
ES5 syntax DEMO
function getLinks() {
var links = document.querySelectorAll('.link');
var arr = [];
for (var i = 0; i < links.length; i++) {
arr.push(links[i].value);
}
return arr;
}
2) Object DEMO
This utilises a data-id attribute as the key for the link values.
<input class="link" data-id="1" value="sdfs" />
This time we create an object with reduce instead.
function getLinks() {
const links = document.querySelectorAll('.link');
return [...links].reduce((obj, link) => {
const id = link.dataset.id;
obj[id] = link.value;
return obj;
}, {});
}
OUTPUT
{
1: "sdfs"
2: "34"
3: "min"
4: "987"
}
ES5 Syntax DEMO
function getLinks() {
const links = document.querySelectorAll('.link');
var obj = {};
for (var i = 0; i < links.length; i++) {
let id = links[i].dataset.id;
obj[id] = links[i].value;
}
return obj;
}
task_linkin the object each time with the link from the next input in the iteration.