I have an issue with the arrays.
My requirement: I have an object say
data = {
192.168.2.1: ["alpha", "beta", "delta"],
192.168.2.2: ["alpha"],
192.168.2.3: ["delta"],
192.168.2.4: []
}
I want to merge all the values (arrays) into one array so that I can read it from UI.
Desired Output: [alpha, beta, delta]
Current implementation:
var allControllerList = [];
var uniqueControllerList = [];
$.each(data, function(i, el){
allControllerList = allControllerList.concat(el);
});
$.each(allControllerList, function(index, el) {
if($.inArray(el, uniqueControllerList) === -1) uniqueControllerList.push(el);
});
If i want to read it on UI, I need to do this again:
<select id='ssid-list' multiple='multiple'>
<% _.each(uniqueControllerList, function(ssid, index) { %>
<option value='<%=controllerIp+ssid%>'>
<%=ssid%>
</option>
<% }); %>
</select>
I am reading an array three times, I was looking for a more efficient implementation. (Underscore, jQuery or JS).
Thanks,