Step1:
Welcome to designer blog, Here we are going to discuss , how to add the names in the passenger
list array
var passengerList = ["Babu", "kumar", "Raja"];
Step2:
We have to initialize two parameters with your own choice...
here we have declared name and list here...
list is called passengerList and name which we are going to add manual while calling the function
Step3:
Function name called addpessanger
function addpassanger(name, list) {
if (list.length == 0) {
list.push(name);
}
else {
for (var i = 0; i < list.length; i++) {
if (list[i] == undefined) {
list[i] = name;
return list;
}
else if (i == list.length-1)
{
list.push(name);
return list;
}
}
}
}
Step4:
addpassanger("faizal", passengerList);
addpassanger("Ashley Smith", passengerList);
output:
console panel :
passengerList;
["Ashley Smith", "Kumar", "Arun"];
Welcome to designer blog, Here we are going to discuss , how to add the names in the passenger
list array
var passengerList = ["Babu", "kumar", "Raja"];
Step2:
We have to initialize two parameters with your own choice...
here we have declared name and list here...
list is called passengerList and name which we are going to add manual while calling the function
Step3:
Function name called addpessanger
function addpassanger(name, list) {
if (list.length == 0) {
list.push(name);
}
else {
for (var i = 0; i < list.length; i++) {
if (list[i] == undefined) {
list[i] = name;
return list;
}
else if (i == list.length-1)
{
list.push(name);
return list;
}
}
}
}
Step4:
addpassanger("faizal", passengerList);
addpassanger("Ashley Smith", passengerList);
output:
console panel :
passengerList;
["Ashley Smith", "Kumar", "Arun"];
No comments:
Post a Comment