i have a very easy question, i need to create an array list from function arguments, so far i managed to alert them one by one, but can’t create a list:
<span onclick="show_flights(1,2,3,4);">text</span>
and function
function show_flights() {
var list='';
for (var x = 0; x < arguments.length; x++) {
alert(arguments[x]);
list.append(arguments[x]);
};
alert(list);
thank you everybody for help, i really appreciate it!
You could just convert the
argumentsobject directly to an array:If you’re interested in the details of how/why this actually works, have a read through the ECMAScript spec, in particular the section on the
Array.prototype.slicemethod. To sum it up very briefly, the method will attempt to create an array from the object on which it is called (itsthisvalue), by iterating over its properties and adding them to that new array (via the internal mechanism[[DefineOwnProperty]]).