<html>
<head> <h1>String Array
Operations</h1></head>
<body>
<button
onclick="Rev()">Reverse</button>
<button
onclick="Shift1()">Shift</button>
<button
onclick="Unshift1()">Unshift</button>
<button
onclick="Push1()">Push</button>
<button onclick="Pop1()">Pop</button>
<button
onclick="Merging()">Merge</button>
<script type="text/javascript">
var
arr=[], arr1=[];
var
n,i,j, str,cct;
function
Rev()
{
n=parseInt(prompt("Enter
the array size"));
document.write("Strings
are:"+"</br>")
for(i=0;i<n;i++)
{
str=prompt("Enter the
String:"+" "+(i+1))
arr[i]=str;
document.write(arr[i]+"<br/>")
}
arr.reverse();
document.write("Strings
are reversing:"+"</br>");
for(j=0;j<arr.length;j++)
{
document.write(arr[j]+"<br/>");
}
}//Rev
Function ends
function
Shift1()//Push Function
{
n=parseInt(prompt("Enter
the array size"));
document.write("Strings
are:"+"</br>")
for(i=0;i<n;i++)
{
str=prompt("Enter
the String:"+" "+(i+1))
arr[i]=str;
document.write(arr[i]+"<br/>")
}
arr.shift();
document.write("Array
after Shift"+"</br>");
for(j=0;j<arr.length;j++)
{
document.write(arr[j]+"<br/>");
}
}
function
Unshift1()//Push Function
{
n=parseInt(prompt("Enter
the array size"));
document.write("Strings
are:"+"</br>")
for(i=0;i<n;i++)
{
str=prompt("Enter
the String:"+" "+(i+1))
arr[i]=str;
document.write(arr[i]+"<br/>")
}
cct=prompt("Enter
the String to add to the array:");
arr.unshift(cct);
document.write("Array
after Unshift"+"</br>");
for(j=0;j<arr.length;j++)
{
document.write(arr[j]+"<br/>");
}
}
function
Push1()//Push Function
{
n=parseInt(prompt("Enter
the array size"));
document.write("Strings
are:"+"</br>")
for(i=0;i<n;i++)
{
str=prompt("Enter
the String:"+" "+(i+1))
arr[i]=str;
document.write(arr[i]+"<br/>")
}
p=prompt("Enter
the String to Push");
arr.push(p);
document.write("Array
after Pushing the String:"+ p +"</br>");
for(j=0;j<arr.length;j++)
{
document.write(arr[j]+"<br/>");
}
}
function
Pop1()
{
n=parseInt(prompt("Enter
the array size"));
document.write("Strings
are:"+"</br>")
for(i=0;i<n;i++)
{
str=prompt("Enter
the String:"+" "+(i+1))
arr[i]=str;
document.write(arr[i]+"<br/>")
}
p=arr.length;
arr.pop(p);
document.write("Array
after Popping the String:" +"</br>");
for(j=0;j<arr.length;j++)
{
document.write(arr[j]+"<br/>");
}
}
function
Merging()
{
n=parseInt(prompt("Enter
the 1st Array size"));
document.write("First
Array Elements are:"+"</br>")
for(i=0;i<n;i++)
{
str=prompt("Enter
the String:"+" "+(i+1))
arr[i]=str;
document.write(arr[i]+"<br/>")
}
n=parseInt(prompt("Enter
the 2nd Array size"));
document.write("Second
Array Elements are:"+"</br>")
for(i=0;i<n;i++)
{
str=prompt("Enter
the String:"+" "+(i+1))
arr1[i]=str;
document.write(arr1[i]+"<br/>")
}
cct=arr.concat(arr1);
document.write("After
Concatenating"+"<br/>"+cct);
}
</script>
</body>
</html>
Output:
Output:
Python is an open-source, high level, interpreted programming language which offers great opportunities for object-oriented programming. Choosing a python training program from Red Prism Group, which is best training institute for python in noida.
ReplyDelete