-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJS_Array_mEthod1.js
52 lines (36 loc) · 1.25 KB
/
JS_Array_mEthod1.js
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
// // Splicing and Slicing Arrays
// // The splice() method adds new items to an array.
// // The slice() method slices out a piece of an array.
// JavaScript Array splice()
// The splice() method can be used to add new items to an array:
let person=["Jami","Ehtisham","Shahjahan","Hukayu"];
let teacher=["Farhat","Mandi","DGkhna"];
person.splice(2,0,"Ghouse","Ali");
// person.slice(2);
person.sort();
person.reverse();
console.log(person.toString());
person.splice(2,4);
console.log(person.toString());
// The slice() method slices out a piece of an array into a new array.
// This example slices out a part of an array starting from array element 1 ("Orange"):
person.slice(2);
console.log(person.toString);
console.log(teacher.slice(2,3).toString());
//======================================sorting the no by using function-----------------------
const no=[21,22,31,12,21,11,1,2];
no.sort(function(a,b){return b-a});
console.log("Sorting tha no array in decending :");
console.log(no);
function maxaara(arr){
console.log("The maximum value is :");
return Math.max.apply(null,arr);
}
let m=no.map(multipli);
console.log(m);
function multipli(value,index,array)
{
console.log("Multiplication of 2 :");
return value*2;
}
console.log(maxaara(no));