Assignment 2
Assignment 2
Assignment 2
Answer :--
<!DOCTYPE html>
<html>
<head>
</head>
<body>
flower[0]="Rose";
flower[1]="Lily";
flower[2]="Lotus";
flower[3]="Sunflower";
flower[4]="MarieGold";
for(i=0;i<flower.length;i++)
document.writeln("<i>"+flower[i]+"<br>")
document.fgColor="Gold";
</script>
</body>
</html>
2> How to add and sort element in array ? Explain with example
Answer :---
<!DOCTYPE html>
<html>
<head>
<title>Array updation</title>
</head>
<body>
flower[1]="Lily"; flower[2]="Lotus";
flower[3]="Sunflower"; flower[4]="MarieGold";
flower.push("Turnip");
for(i=0;i<flower.length;i++)
document.write(flower[i]+"<br>"); }
flower.sort();
for(i=0;i<flower.length;i++)
document.writeln("<i>"+flower[i]+"<br>");
} document.fgColor="Gold";
</script>
</body>
</html>
3> Differentiate between join() and concat() methods of array object Answer
:---
Sr no. Join() method() Concat() method
1 Using join() method we can separate array Using concat() method we can’t separate array
element by giving any symbol,number and element by using any type of symbol,number and
character. character.
2 Syntax :-- join(“?”) or join() Syntax :-- conact()
4> Write a javascript that will replace following specified value with another value in string.
Answer :--
<!DOCTYPE html>
<html>
<head>
<title>String Manipulation</title>
</head>
<body>
</script>
</body>
</html>
html>
<html>
<head>
<title>Age vali</title>
function salary_emp()
</script>
</head>
<body>
salary_emp() </script>
</body>
</html>
Answer :-
<!DOCTYPE html>
<html>
<head>
<title>String Manipulation</title>
</head>
<body>
</script>
</body>
</html>
7> explain javascript method to find Unicode of a character of and find character from Unicode.
Answer :--
To find Unicode of particular character we have charCodeAt(ascii code )method and to find character of
from ascii code we have fromCharCode(char) method.
Example :--
<!DOCTYPE html>
<html>
<head>
<title>String Manipulation</title>
</head>
<body>
var c="w";
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>ARRAY</title>
</head>
<body>
fruit[1]="APPLE"
fruit[2]="WATERMELON"
fruit[3]="ORANGE" fruit[4]="GRAPES"
fruit[5]="COCONUT"
fruit.sort();
for(i=0;i<fruit.length;i++)
document.write(fruit[i]+"<br>");
</script>
</body>
</html>
9> write a javascript function to insert a string at within a string at particular position.
<html>
<head>
<title>String Manipulation</title>
function string1()
{
var email="[email protected]";
</script>
</head>
<body>
<h1>String Manipulation</h1>
<script type="text/javascript">
string1()
</script>
</body>
</html>
10> Write the use of charAt() and indexOf() with syntax and example
Answer :--
*charAt(index):-- this method is responsible for return a character from particular index.
*indexOf(char) :-- This method is responsible for return a index from particular character.
<!DOCTYPE html>
<html>
<head>
<title>String Manipulation</title>
</head>
<body>
3 :"+myLastName.charAt(3));
</script>
</body>
</html>
Answer :---
<!DOCTYPE html>
<html>
<head>
<title>String Manipulation</title>
</head>
<body>
Arya";
</script>
</body>
</html>