-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray9.html
More file actions
51 lines (38 loc) · 1.7 KB
/
Array9.html
File metadata and controls
51 lines (38 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<h3> demo on array methods</h3>
<script>
const a=[21,22,30,55,60,70,30,90];
let str="notepad plus plus";
document.write( `Eles ${a}<br>`);
document.write( `Str ${str}<br>`);
//includes()->searching in arr and str(return true or false)
document.write( `10 found ? ${a.includes(10)}<br>`);
document.write( `55 found ? ${a.includes(55)}<br>`);
document.write( `plus found ? ${str.includes('plus')}<br>`);
document.write( `t found ? ${str.includes('t')}<br>`);
//indexOf() ->return position(index no)of element, if multiple occrence then return 1st occrence and if not found then return -1
document.write( `plus index : ${str.indexOf('plus')}<br>`);
document.write( `p index : ${str.indexOf('p')}<br>`);
document.write( `j index : ${str.indexOf('j')}<br>`);
document.write( `80 index : ${a.indexOf(80)}<br>`);
document.write( `30 index : ${a.indexOf(30,5)}<br>`);
document.write( `p index : ${str.indexOf('p',5)}<br>`);
document.write( `p index : ${str.indexOf('p',str.indexOf('p')+1)}<br>`);
//lastIndexOf()->
//reverse()->reverse array , String not supported
a.reverse();
document.write(`reverse eles ${a}<br>`);
//toString()-> convert array into string
document.write(`${a.toString()}<br>`);
document.write(`${str.toString()}<br>`);
//sort()
a.sort();
document.write(`sort eles: ${a}<br>`);
let names=['sudeep','sourabh','vivek','ankit','soumy'];
names.sort();
document.write(`sorted names: ${names}<br>`);
//join()=> joining elements with specified symbol
document.write(`${a.join("@")}<br>`);
//use and throw concept
document.write(`${[10,20,30].includes(20)}<br>`); //anonymous array
document.write(`${"welcome".indexOf("come")}`);//anonymous string
</script>